I’ve been comparing requests (Vue File Agent vs Uppy) using Fiddler.
The only difference I noticed, was the ‘accept’ header. It was set to ‘application/json’ in VFA’s request, but to ‘/’ in Uppy’s request.
I have since modified my Uppy code to set the header to ‘application/json’ as well.
Here’s the working VFA request on production:
POST https://contentbase.com/api/admin/UploadPackageImage HTTP/1.1
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9,nl-NL;q=0.8,nl;q=0.7
Accept: application/json
Connection: keep-alive
Content-Length: 382990
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryou6nPHrBCr6xeb1M
Host: contentbase.com
Origin: https://contentbase.com
Referer: https://contentbase.com/admin/public-package/1247/
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "Windows"
sec-ch-ua: "Google Chrome";v="107", "Chromium";v="107", "Not=A?Brand";v="24"
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: same-origin
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36
------WebKitFormBoundaryou6nPHrBCr6xeb1M
Content-Disposition: form-data; name="idPackage"
1247
------WebKitFormBoundaryou6nPHrBCr6xeb1M
Content-Disposition: form-data; name="file"; filename="Template001.jpg"
Content-Type: image/jpeg
[image data edited out]
------WebKitFormBoundaryou6nPHrBCr6xeb1M--
Here’s the non-working Uppy request on localhost:
POST https://localhost:7006/api/upload/UploadFile2 HTTP/1.1
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9,nl-NL;q=0.8,nl;q=0.7
accept: application/json
Connection: keep-alive
Content-Length: 383300
Content-Type: multipart/form-data; boundary=----WebKitFormBoundarydCIiNLTeyTEwkI4h
Host: localhost:7006
Origin: https://localhost:7006
Referer: https://localhost:7006/
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "Windows"
sec-ch-ua: "Google Chrome";v="107", "Chromium";v="107", "Not=A?Brand";v="24"
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: same-origin
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36
------WebKitFormBoundarydCIiNLTeyTEwkI4h
Content-Disposition: form-data; name="relativePath"
null
------WebKitFormBoundarydCIiNLTeyTEwkI4h
Content-Disposition: form-data; name="name"
Template001.jpg
------WebKitFormBoundarydCIiNLTeyTEwkI4h
Content-Disposition: form-data; name="type"
image/jpeg
------WebKitFormBoundarydCIiNLTeyTEwkI4h
Content-Disposition: form-data; name="idPackage"
1247
------WebKitFormBoundarydCIiNLTeyTEwkI4h
Content-Disposition: form-data; name="file"; filename="Template001.jpg"
Content-Type: image/jpeg
[image data edited out]
------WebKitFormBoundarydCIiNLTeyTEwkI4h--
Save for the ‘type, name & relativePath’ multipart content that Uppy adds, the requests are identical.
(The only header that was edited out, was the cookie header. These are wildly different. But it can’t possibly cause the problem, anyway.)
So why won’t my server side method accept the additional idPackage parameter?
[HttpPost]
public async Task<IActionResult> UploadFile2(IFormFile file, int idPackage)
{
string output = $"{file.FileName} - {file.Length} - {idPackage}";
return Ok(output);
}
When I add ‘string type, string name, string relativePath’ to the method, in order to try to get it to match with the upload request, I get a bad request error.
Is there any way I can tell Uppy not to include name, type and relativePath in the generated request?
This is the only difference in requests. That’s got to be the cause.
Why can’t I just add type, name and relativePath to my upload method to make it work?
Any advice on making it work, no matter how, will be greatly appreciated.