I am currently facing an issue with uploading files via an API call using the PUT method. After successfully uploading a file, I am encountering problems where the resulting file size is larger than expected and cannot be opened. For example, a 234 kb jpg file becomes 352 kb after upload, while a 12 kb docx file turns into 17 kb.
var contentType = file.type;
var reader = new FileReader();
reader.onload = function (e) {
var rawData = reader.result;
$http({
url: appSettings.serverPath + '/File/' + fileId + '/Content',
method: 'PUT',
headers: { 'Content-Type': undefined },
data: rawData,
transformRequest: []
}).success(function (data, status, headers, config) {
deferred.resolve(data);
}).error(function (error) {
deferred.reject(error);
});
};
reader.readAsBinaryString(file);
Despite trying different content types in the header, the issue persists.
Attempted methods such as readAsArrayBuffer and readAsDataURL on a FileReader object did not solve the problem either. The former resulted in a file with 0 bytes, while the latter led to significantly larger file sizes that remained corrupted and inaccessible. Is there a specific encoding process or any other solution required to ensure accurate data transfer?
Any help would be greatly appreciated! Thank you.