Skip to content

Commit

Permalink
always upload file in chunks
Browse files Browse the repository at this point in the history
  • Loading branch information
emadehsan committed Jul 3, 2018
1 parent d4f94db commit a3fbdbe
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,24 +390,26 @@ const REST = {

let fileMBs = fileSize / (1024*1024);
console.log('File size in MBs: ', fileMBs);
if (fileMBs > 100) {
console.log('File size more than 100 MBs: ', fileMBs, ' MBs', ' Upload in CHUNKS');
return await REST.uploadFileChunks(UploadURL, fileBuffer);
}

console.log('Uploading file the normal way since less than 100MBs');
const resp = await axios.put(UploadURL, fileBuffer,{
headers: {
'Content-Type': ' video/mp4',
'x-ms-blob-type': 'BlockBlob'
},
maxContentLength: fileSize
});

// console.log('Status: ', resp.status);

// resp.status == 201
return true;

// for all cases, uploading in chunks
return await REST.uploadFileChunks(UploadURL, fileBuffer);

// previously, only the files larger than 100MBs were uploaded in chunks
// if (fileMBs > 100) {
// console.log('File size more than 100 MBs: ', fileMBs, ' MBs', ' Upload in CHUNKS');
// return await REST.uploadFileChunks(UploadURL, fileBuffer);
// }
// console.log('Uploading file the normal way since less than 100MBs');
// const resp = await axios.put(UploadURL, fileBuffer,{
// headers: {
// 'Content-Type': ' video/mp4',
// 'x-ms-blob-type': 'BlockBlob'
// },
// maxContentLength: fileSize
// });
// // console.log('Status: ', resp.status);
// // resp.status == 201
// return true;
} catch (e) {
console.log('uploadFile: ERROR: ', e);
return false;
Expand Down

0 comments on commit a3fbdbe

Please sign in to comment.