Storage REST api not properly handling multipart/form-data PUT request

Hi,


I am trying to upload files to storage via the REST API in javascript. But, it seems that when I “PUT” a file to storage, it does not properly handle multipart/form-data and saves the multipart/form-data boundaries as part of the document. This causes corruption of the file.

var formData = new FormData();
formData.append(file.name, file);
var uploadUrl = this.getSignedUrl(‘storage/file’, file.name, null);
var xhr = new XMLHttpRequest();
xhr.open(“PUT”, uploadUrl, true);
xhr.setRequestHeader(‘Accept’, ‘application/json’);
xhr.onreadystatechange = function(e) {
if (xhr.readyState == 4) {
var response = null;
if (xhr.status == 200) {
try {
response = JSON.parse(xhr.response);
} catch (e) {
}
}

if (callback) {
callback(response);
}
}
};
xhr.send(formData);

Attached is a zipfile with the original PPT, the corrupted PPT (downloaded from storage), and the Wireshark dump of the upload.

Please advise on how I can properly upload multipart/form-data to storage without corrupted documents. Thanks.

Best Regards,
Patrick

Hi,

Please see post 471102 and advise on how the problem can be resolved.

Best Regards,
Patrick


Hi Patrick,


Thanks for your inquiry. We’re sorry about that. We were adding examples for various platforms and so far we have added these examples for .NET, Java, PHP, Python, Android, Ruby. However, I’ve logged a task to provide you an example. This task has been logged under ticket id SUPPORT-1059 in our issue tracking system. Meanwhile, can you please clarify the source code about the method getSignedUrl? Because we don’t have such function in javascript. We’re sorry for the inconvenience.

Sure. Here are the relevant functions:


function getSignedUrl(cmd, filename, qs) {
if (cmd) {
var uri = new URI(aspose.baseUrl);
uri.segment(cmd);
if (filename) {
uri.segment(filename);
}
if (qs) {
uri.query(qs);
}
return this.sign(uri.toString());
}
}

function sign(url) {
var signedUrl = null;
if (url) {
var uri = new URI(url);
uri.addQuery(“appSID”, appSID);
var signature = CryptoJS.HmacSHA1(uri.toString(), appKey);
var encodedSignature = signature.toString(CryptoJS.enc.Base64);
encodedSignature = encodedSignature.replace(/=$/, ‘’);
uri.addQuery(“signature”, encodedSignature);
signedUrl = uri.toString();
}
return signedUrl;
};

Also, where do I find this support task (SUPPORT-1059)?


Best Regards,
Patrick

Hi Patrick,


Thanks for the information. We will notify you in this thread once it is resolved. Furthermore, you can ask about the update within the current forum thread. I’ve logged this information in our issue tracking system and we will get back to you soon.

Hi Patrick,

We’re sorry about the delayed response. You can find Sign and UploadFileBinary methods here in the following link: https://docs.aspose.cloud/slides/working-with-files-folders-and-storage/

Please do let me know in case of any confusion or questions.