-
Notifications
You must be signed in to change notification settings - Fork 189
Upload with uptoken and stream #31
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3ec2aa6
Upload with uptoken and stream
ikbear df3ee62
Update changelog doc
ikbear 702ac42
Add enableCrc32Check option to stream upload
ikbear b46acbf
fix fd close and enableCrc32Check bug
ikbear c55014b
fix crc32 and action string bug
ikbear File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,18 @@ | ||
| #CHANGELOG | ||
|
|
||
| ## v2.3.2 | ||
|
|
||
| 2012-12-31 | ||
|
|
||
| updated: | ||
|
|
||
| - 修复crc32编码 | ||
| - 修复使用UploadToken方式上传时流式上传bug,流式上传不检查crc32 | ||
|
|
||
| ## v2.3.0 | ||
|
|
||
| 2012-11-23 | ||
|
|
||
| updated: | ||
|
|
||
| - 启用新的 uploadToken(上传凭证)上传方式,可由客户方业务服务器生成上传凭证。上传前无需请求七牛云存储,减少http请求。 | ||
| - 增加断点续上传支持,并行断点传输速度更快 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| var fs = require('fs'); | ||
| var path = require('path'); | ||
| var mime = require('mime'); | ||
| var crypto = require('crypto'); | ||
| var crc32 = require('crc32'); | ||
|
|
||
| // ------------------------------------------------------------------------------------------ | ||
| // func encode | ||
|
|
@@ -15,34 +15,22 @@ exports.encode = function(v) { | |
| return exports.base64ToUrlsafe(encoded); | ||
| }; | ||
|
|
||
| exports.generateActionString = function(localFile, bucket, key, mimeType, customMeta, enableCrc32Check) { | ||
| if (!fs.existsSync(localFile)) { | ||
| exports.generateActionString = function(bucket, key, mimeType, customMeta, crc32) { | ||
| if (!key) { | ||
| console.error("Please specify your key!"); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 需了解些 nodejs 的报错惯例。 |
||
| return; | ||
| } | ||
| if (key == null) { | ||
| var today = new Date(); | ||
| key = crypto.createHash('sha1').update(localFile + today.toString()).digest('hex'); | ||
| } | ||
| var entryUri = bucket + ":" + key; | ||
| if (mimeType === "") { | ||
| mimeType = mime.lookup(localFile); | ||
| if (mimeType === "") { | ||
| mimeType = "application/octet-stream"; | ||
| } | ||
| if (!mimeType) { | ||
| mimeType = "application/octet-stream"; | ||
| } | ||
| var actionParams = '/rs-put/' + this.encode(entryUri) + '/mimeType/' + this.encode(mimeType); | ||
| if (customMeta !== "") { | ||
| actionParams += '/meta/' + this.encode(customMeta); | ||
| } | ||
| if (enableCrc32Check) { | ||
| var fileStat = fs.statSync(localFile); | ||
| var fileSize = fileStat.size; | ||
| var buf = new Buffer(fileSize); | ||
| var fd = fs.openSync(localFile, 'r'); | ||
| fs.readSync(fd, buf, 0, fileSize, 0); | ||
| var fileCrc32 = parseInt("0x" + crc32(buf)).toString(); | ||
| actionParams += '/crc32/' + fileCrc32; | ||
| } | ||
| if ((crc32 !== undefined) && (crc32 !== null) && (crc32 !== "")) { | ||
| actionParams += '/crc32/' + crc32; | ||
| } | ||
| return actionParams; | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fd 不需要 close 么?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
需要。我加上。