Jump to content
  • 0

Post/Put File Using API and C#


ForeGolfer

Question

Has anyone been able to issue a post or put operation for a file insert/update using the Caspio API?  I keep getting a 400 error?   I was getting an authorization error, but I fixed that and I'm now stuck on the Bad Request error.

Below is my code:

String url =   "https://<myAcctId.>caspio.com/rest/v2/files";

String filePath = "\\\\fileserver\\DEV\\2023\\Case\8222_APPR_2312300915129474.pdf";

                HttpClient client = new HttpClient();

                HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, url);

                request.Headers.Add("accept", "application/json");

                request.Headers.Add("Authorization", auth);

                MultipartFormDataContent content = new MultipartFormDataContent();

                content.Add(new ByteArrayContent(File.ReadAllBytes(filePath)), "File", Path.GetFileName(filePath));

                request.Content = content;

                request.Content.Headers.ContentType = new MediaTypeHeaderValue("multipart/form-data");

                response = await client.SendAsync(request);

 

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Could you explain which programming language are you using?

I think that the error might be due to the file path declaration, it seems like you are missing one "\" after "Case".

If this is C#, I use the format that starts with the @ to get system files, so I can skip repeating the "\" all the time and just copy and paste the routes from explorer, like: 

String filePath = @"C:\Directory\Somefile.pdf";

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...