Content-Type boundary issue when uploading a file

Hi

I have a chrome extension that is using backendless to upload a file. The code is :

		var request = new XMLHttpRequest();
		request.open('POST', 'https://api.backendless.com/<API-KEY-OBSCURED>/<REST_API_KEY_OBSCURED>/files/binary/testName.webm?overwrite=true');
		request.setRequestHeader('Content-Type','multipart/form-data; boundary=RECORD_BOUNDARY');
		request.onload = function() {
			// Do Something 		
		};

		var recorderBlob = { body: recorder.getBlob(), name: "testName.webm" };
		request.send(recorderBlob);	
                   // recorder.getBlob is a video/webm object containing a recorded screen

But the response returns a 400 with the following :

response = “{“code”:8002,“message”:“Could not parse request with message: Unexpected end of input, status code 400, headers POST /D5F0DFFA-0C36-CC73-FF39-171676325B00/A2C876F2-6E9C-EE22-FF0E-7C00506E6700/files/binary/testName.webm?overwrite=true”,“errorData”:{}}”

The documentation for the binary file upload does not describe what to do with the ‘boundary’ directive, but the API seems to need it.

Please can you advise ?

Paul

Hi Paul,

I think it is an error in the documentation. I see the Example section here uses the following: Content-Type: text/plain. Could you please try making that change and see if it works for you?

Regards,
Mark

Hi Mark

Thanks for the quick reply.

I changed the content-type to text/plain.

Unfortunately, I still get this response expecting the ‘multipart/form-data’ :slight_smile:

response = “{“code”:6010,“message”:“Corrupted multipart request. Header Content-Type must be set to value multipart/form-data”,“errorData”:{}}”

Any ideas ?

Thanks
Paul

Hi Mark

the example you showed actually shows that it needs a PUT rather than a POST. When using a PUT rather than a POST with that content type, the response returns the 200 with the url to the file.

Though, I now need to understand why the file here, doesn’t look like a valid file - https://api.backendless.com/D5F0DFFA-0C36-CC73-FF39-171676325B00/A2C876F2-6E9C-EE22-FF0E-7C00506E6700/files/testName.webm

Any thoughts there ?

Cheers
Paul

Hi Paul

POST method is needed for basic file uploading, and PUT is for saving files from byte arrays. A working cURL sample attached.

curlSample.txt (14.7 KB)

I’ve just uploaded a .webm file successfully, please verify whether your base64 body is valid.

Regards,
Anton

Hi Anton

Thanks for that.

My version had some tags for the mime type at the beginning. I’ve stripped those and it now uploads successfully!!

Thanks!

Paul