Permalink
Browse files

fix crc32 and action string bug

  • Loading branch information...
ikbear committed Jan 14, 2013
1 parent b46acbf commit c55014b8a475b3e3d786ae346b9a406ad5615a00
Showing with 22 additions and 13 deletions.
  1. +12 −4 lib/auth.js
  2. +7 −6 lib/rs.js
  3. +3 −3 lib/util.js
View
@@ -12,12 +12,20 @@ function UploadToken(opts) {
UploadToken.prototype.generateSignature = function() {
var params = {
- "scope": this.scope,
"deadline": this.expires + Math.floor(Date.now() / 1000),
- "callbackUrl": this.callbackUrl,
- "callbackBodyType": this.callbackBodyType,
- "customer": this.customer,
};
+ if (this.scope !== null) {
+ params["scope"] = this.scope;
+ }
+ if (this.callbackUrl !== null) {
+ params["callbackurl"] = this.callbackUrl;
+ }
+ if (this.callbackBodyType !== null) {
+ params["callbackBodyType"] = this.callbackBodyType;
+ }
+ if (this.customer !== null) {
+ params["customer"] = this.customer;
+ }
var paramsString = JSON.stringify(params)
return util.encode(paramsString);
};
View
@@ -117,17 +117,17 @@ Service.prototype.uploadFile = function(upToken, key, mimeType, localFile, onret
});
};
-Service.prototype.uploadWithToken = function(uploadToken, stream, key, mimeType, customMeta, callbackParams, enableCrc32Check, onret) {
+Service.prototype.uploadWithToken = function(uploadToken, stream, key, mimeType, customMeta, callbackParams, crc32, onret) {
/*
- * func UploadWithToken(uploadToken, stream, key, mimeType, customMeta, callbackParams, enableCrc32Check, onret) => (data PutRet, code int, err Error)
+ * func UploadWithToken(uploadToken, stream, key, mimeType, customMeta, callbackParams, crc32, onret) => (data PutRet, code int, err Error)
* 使用upload_token以multipart/form-data形式上传ReadStream流
**/
var bucket = this.bucket;
if (!mimeType) {
mimeType = "application/octet-stream";
}
- var actionString = util.generateActionString(bucket, key, mimeType, customMeta, enableCrc32Check);
+ var actionString = util.generateActionString(bucket, key, mimeType, customMeta, crc32);
if (callbackParams === null) {
callbackParams = {
"bucket": bucket,
@@ -165,7 +165,8 @@ Service.prototype.uploadFileWithToken = function(uploadToken, localFile, key, mi
onret({code: -1, error: err.toString(), detail: err});
return;
}
- var stream = fs.createReadStream(localFile);
+ var fileCrc32 = null
+ , stream = fs.createReadStream(localFile);
if (enableCrc32Check) {
var fileStat = fs.statSync(localFile)
@@ -175,10 +176,10 @@ Service.prototype.uploadFileWithToken = function(uploadToken, localFile, key, mi
fs.readSync(fd, buf, 0, fileSize, 0);
fs.closeSync(fd);
- enableCrc32Check = parseInt("0x" + crc32(buf)).toString();
+ fileCrc32 = parseInt("0x" + crc32(buf)).toString();
}
- self.uploadWithToken(uploadToken, stream, key, mimeType, customMeta, callbackParams, enableCrc32Check, onret);
+ self.uploadWithToken(uploadToken, stream, key, mimeType, customMeta, callbackParams, fileCrc32, onret);
});
};
View
@@ -15,7 +15,7 @@ exports.encode = function(v) {
return exports.base64ToUrlsafe(encoded);
};
-exports.generateActionString = function(bucket, key, mimeType, customMeta, enableCrc32Check) {
+exports.generateActionString = function(bucket, key, mimeType, customMeta, crc32) {
if (!key) {
console.error("Please specify your key!");
return;
@@ -28,8 +28,8 @@ exports.generateActionString = function(bucket, key, mimeType, customMeta, enabl
if (customMeta !== "") {
actionParams += '/meta/' + this.encode(customMeta);
}
- if (enableCrc32Check) {
- actionParams += '/crc32/' + enableCrc32Check;
+ if ((crc32 !== undefined) && (crc32 !== null) && (crc32 !== "")) {
+ actionParams += '/crc32/' + crc32;
}
return actionParams;
}

0 comments on commit c55014b

Please sign in to comment.