Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crc32 #362

Merged
merged 2 commits into from
Jul 1, 2020
Merged

Crc32 #362

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 3 additions & 37 deletions examples/form_upload_simple.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,13 @@ var putPolicy = new qiniu.rs.PutPolicy(options);

var uploadToken = putPolicy.uploadToken(mac);
var config = new qiniu.conf.Config();
var localFile = '/Users/jemy/Downloads/VIDEO_20191008_093955.mp4.zip';
var localFile = '/Users/jemy/Downloads/download.csv';
// config.zone = qiniu.zone.Zone_z0;
var formUploader = new qiniu.form_up.FormUploader(config);
var putExtra = new qiniu.form_up.PutExtra();

// bytes
// formUploader.put(uploadToken, null, "hello", null, function(respErr,
// respBody, respInfo) {
// if (respErr) {
// throw respErr;
// }
//
// if (respInfo.statusCode == 200) {
// console.log(respBody);
// } else {
// console.log(respInfo.statusCode);
// console.log(respBody);
// }
// });

// file
putExtra.fname = 'testfile16.mp4';
putExtra.fname = 'test01.csv';
putExtra.crc32 = 3497766758;
formUploader.putFile(uploadToken, null, localFile, putExtra, function (respErr,
respBody, respInfo) {
if (respErr) {
Expand All @@ -47,22 +32,3 @@ formUploader.putFile(uploadToken, null, localFile, putExtra, function (respErr,
console.log(respBody);
}
});

// test query zone frequently when config.zone==null;
setTimeout(upload, 1500);
function upload () {
putExtra.fname = 'testfile17.mp4';
formUploader.putFile(uploadToken, null, localFile, putExtra, function (respErr,
respBody, respInfo) {
if (respErr) {
throw respErr;
}

if (respInfo.statusCode == 200) {
console.log(respBody);
} else {
console.log(respInfo.statusCode);
console.log(respBody);
}
});
}
16 changes: 11 additions & 5 deletions qiniu/storage/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function PutExtra (fname, params, mimeType, crc32, checkCrc) {
this.params = params || {};
this.mimeType = mimeType || null;
this.crc32 = crc32 || null;
this.checkCrc = checkCrc || 1;
this.checkCrc = checkCrc || true;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里改为this.checkCrc = checkCrc || false就行了,否则是强制checkCrc=true。

}

FormUploader.prototype.putStream = function (uploadToken, key, fsStream,
Expand Down Expand Up @@ -122,10 +122,16 @@ function createMultipartForm (uploadToken, key, fsStream, putExtra, callbackFunc
fileBody.push(data);
});

fsStream.on('end', function () {
fileBody = Buffer.concat(fileBody);
var bodyCrc32 = parseInt('0x' + getCrc32(fileBody));
postForm.field('crc32', bodyCrc32);
fsStream.on('end', function() {
if (putExtra.checkCrc) {
if (putExtra.crc32 == null) {
fileBody = Buffer.concat(fileBody);
var bodyCrc32 = parseInt('0x' + getCrc32(fileBody));
postForm.field('crc32', bodyCrc32);
} else {
postForm.field('crc32', putExtra.crc32);
}
}
});
callbackFunc(postForm);
}
Expand Down