Comparing version 5.0.2 to 6.0.0
@@ -48,2 +48,7 @@ /* | ||
exports.readableStream = readableStream; | ||
exports.prependXAMZMeta = prependXAMZMeta; | ||
exports.isAmzHeader = isAmzHeader; | ||
exports.isSupportedHeader = isSupportedHeader; | ||
exports.isStorageclassHeader = isStorageclassHeader; | ||
exports.extractMetadata = extractMetadata; | ||
@@ -349,2 +354,49 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
} | ||
// Function prepends metadata with the appropriate prefix if it is not already on | ||
function prependXAMZMeta(metaData) { | ||
var newMetadata = Object.assign({}, metaData); | ||
for (var key in metaData) { | ||
if (!isAmzHeader(key) && !isSupportedHeader(key) && !isStorageclassHeader(key)) { | ||
newMetadata["X-Amz-Meta-" + key] = newMetadata[key]; | ||
delete newMetadata[key]; | ||
} | ||
} | ||
return newMetadata; | ||
} | ||
// Checks if it is a valid header according to the AmazonS3 API | ||
function isAmzHeader(key) { | ||
var temp = key.toLowerCase(); | ||
return temp.startsWith("x-amz-meta-") || temp === "x-amz-acl" || temp.startsWith("x-amz-server-side-encryption-") || temp === "x-amz-server-side-encryption"; | ||
} | ||
//Checks if it is a supported Header | ||
function isSupportedHeader(key) { | ||
var supported_headers = ['content-type', 'cache-control', 'content-encoding', 'content-disposition', 'content-language', 'x-amz-website-redirect-location']; | ||
return supported_headers.indexOf(key.toLowerCase()) > -1; | ||
} | ||
//Checks if it is a storage header | ||
function isStorageclassHeader(key) { | ||
return key.toLowerCase() === "x-amz-storage-class"; | ||
} | ||
function extractMetadata(metaData) { | ||
var newMetadata = {}; | ||
for (var key in metaData) { | ||
if (isSupportedHeader(key) || isStorageclassHeader(key) || isAmzHeader(key)) { | ||
if (key.toLowerCase().startsWith("x-amz-meta-")) { | ||
newMetadata[key.slice(11, key.length)] = metaData[key]; | ||
} else { | ||
newMetadata[key] = metaData[key]; | ||
} | ||
} | ||
} | ||
return newMetadata; | ||
} | ||
//# sourceMappingURL=helpers.js.map |
@@ -50,3 +50,3 @@ /* | ||
function ObjectUploader(client, bucketName, objectName, partSize, contentType, callback) { | ||
function ObjectUploader(client, bucketName, objectName, partSize, metaData, callback) { | ||
_classCallCheck(this, ObjectUploader); | ||
@@ -61,6 +61,5 @@ | ||
this.partSize = partSize; | ||
// This is the metadata for the object. | ||
this.metaData = metaData; | ||
// This contentType for the object. | ||
this.contentType = contentType; | ||
// Call like: callback(error, etag). | ||
@@ -98,7 +97,3 @@ this.callback = callback; | ||
var method = 'PUT'; | ||
var headers = { | ||
'Content-Length': chunk.length, | ||
'Content-Type': this.contentType | ||
}; | ||
var headers = Object.assign({}, this.metaData, { 'Content-Length': chunk.length }); | ||
var md5digest = ''; | ||
@@ -136,2 +131,3 @@ | ||
// Give the etag back, we're done! | ||
process.nextTick(function () { | ||
@@ -162,3 +158,3 @@ _this.callback(null, etag); | ||
if (!id) { | ||
_this.client.initiateNewMultipartUpload(_this.bucketName, _this.objectName, _this.contentType, function (err, id) { | ||
_this.client.initiateNewMultipartUpload(_this.bucketName, _this.objectName, _this.metaData, function (err, id) { | ||
if (err) return callback(err); | ||
@@ -253,6 +249,3 @@ | ||
var method = 'PUT'; | ||
var headers = { | ||
'Content-Length': 0, | ||
'Content-Type': this.contentType | ||
}; | ||
var headers = Object.assign({}, this.metaData, { 'Content-Length': 0 }); | ||
var options = { | ||
@@ -259,0 +252,0 @@ method: method, headers: headers, |
@@ -35,3 +35,3 @@ # JavaScript Client API Reference [![Slack](https://slack.minio.io/slack?type=svg)](https://slack.minio.io) | ||
| [`bucketExists`](#bucketExists) | [`fGetObject`](#fGetObject) | [`presignedPutObject`](#presignedPutObject) | [`removeAllBucketNotification`](#removeAllBucketNotification) | | ||
| [`removeBucket`](#removeBucket) | [`putObject`](#putObject) | [`presignedPostPolicy`](#presignedPostPolicy) | [`getBucketPolicy`](#getBucketPolicy) | | | ||
| [`removeBucket`](#removeBucket) | [`putObject`](#putObject) | [`presignedPostPolicy`](#presignedPostPolicy) | [`getBucketPolicy`](#getBucketPolicy) | | | ||
| [`listObjects`](#listObjects) | [`fPutObject`](#fPutObject) | | [`setBucketPolicy`](#setBucketPolicy) | ||
@@ -41,6 +41,7 @@ | [`listObjectsV2`](#listObjectsV2) | [`copyObject`](#copyObject) | | [`listenBucketNotification`](#listenBucketNotification)| | ||
| | [`removeObject`](#removeObject) | | ||
| | [`removeObjects`](#removeObjects) | | ||
| | [`removeIncompleteUpload`](#removeIncompleteUpload) | | ||
## 1. Constructor | ||
@@ -62,6 +63,8 @@ | ||
| `port` | _number_ | TCP/IP port number. This input is optional. Default value set to 80 for HTTP and 443 for HTTPs. | | ||
| `accessKey` | _string_ |accessKey is like user-id that uniquely identifies your account. | | ||
|`secure` | _bool_ |If set to true, https is used instead of http. Default is true. | | ||
|`accessKey` | _string_ |accessKey is like user-id that uniquely identifies your account. | | ||
|`secretKey` | _string_ | secretKey is the password to your account.| | ||
|`secure` | _bool_ |If set to true, https is used instead of http. Default is true. | | ||
|`region` | _string_ |Set this value to override auto bucket region discovery. (Optional)| | ||
|`region` | _string_ |Set this value to override region cache. (Optional)| | ||
|`transport` | _string_ |Set this value to pass in a custom transport. (Optional)| | ||
|`sessionToken` | _string_ |Set this value to provide x-amz-security-token (AWS S3 specific). (Optional)| | ||
@@ -437,3 +440,3 @@ | ||
<a name="putObject"></a> | ||
### putObject(bucketName, objectName, stream, size, contentType[, callback]) | ||
### putObject(bucketName, objectName, stream, size, metaData[, callback]) | ||
@@ -454,3 +457,3 @@ Uploads an object from a stream/Buffer. | ||
|`size` | _number_ | Size of the object (optional). | | ||
|`contentType` | _string_ | Content-Type of the object (optional, default `application/octet-stream`). | | ||
|`metaData` | _Javascript Object_ | metaData of the object (optional). | | ||
| `callback(err, etag)` | _function_ | Non-null `err` indicates error, `etag` _string_ is the etag of the object uploaded. If no callback is passed, a `Promise` is returned. | | ||
@@ -487,3 +490,3 @@ | ||
|`string or Buffer` | _Stream_ or _Buffer_ |Readable stream. | | ||
| `contentType` | _string_ | Content-Type of the object (optional, default `application/octet-stream`). | | ||
| `metaData` | _Javascript Object_ | metaData of the object (optional). | | ||
| `callback(err, etag)` | _function_ |Non-null `err` indicates error, `etag` _string_ is the etag of the object uploaded. | | ||
@@ -502,3 +505,3 @@ | ||
<a name="fPutObject"></a> | ||
### fPutObject(bucketName, objectName, filePath, contentType[, callback]) | ||
### fPutObject(bucketName, objectName, filePath, metaData[, callback]) | ||
@@ -515,3 +518,3 @@ Uploads contents from a file to objectName. | ||
| `filePath` | _string_ | Path of the file to be uploaded. | | ||
| `contentType` | _string_ | Content-Type of the object. | | ||
| `metaData` | _Javascript Object_ | Metadata of the object. | | ||
| `callback(err, etag)` | _function_ | Non-null `err` indicates error, `etag` _string_ is the etag of the object uploaded. If no callback is passed, a `Promise` is returned. | | ||
@@ -526,3 +529,9 @@ | ||
var file = '/tmp/40mbfile' | ||
minioClient.fPutObject('mybucket', '40mbfile', file, 'application/octet-stream', function(err, etag) { | ||
var metaData = { | ||
'Content-Type': 'text/html', | ||
'Content-Language': 123, | ||
'X-Amz-Meta-Testing': 1234, | ||
'example': 5678 | ||
} | ||
minioClient.fPutObject('mybucket', '40mbfile', file, metaData, function(err, etag) { | ||
return console.log(err, etag) // err should be null | ||
@@ -535,3 +544,3 @@ }) | ||
Copy a source object into a new object in the specied bucket. | ||
Copy a source object into a new object in the specified bucket. | ||
@@ -584,3 +593,3 @@ __Parameters__ | ||
| `stat.etag` | _string_ | etag of the object. | | ||
| `stat.contentType` | _string_ | Content-Type of the object.| | ||
| `stat.metaData` | _Javascript Object_ | metadata of the object.| | ||
| `stat.lastModified` | _Date_ | Last Modified time stamp.| | ||
@@ -628,2 +637,49 @@ | ||
<a name="removeObjects"></a> | ||
### removeObjects(bucketName, objectsList[, callback]) | ||
Remove all objects in the objectsList. | ||
__Parameters__ | ||
| Param | Type | Description | | ||
| ---- | ---- | ---- | | ||
| `bucketName` | _string_ | Name of the bucket. | | ||
| `objectsList` | _object_ | list of objects in the bucket to be removed. | | ||
| `callback(err)` | _function_ | Callback function is called with non `null` value in case of error. | | ||
__Example__ | ||
```js | ||
var objectsList = [] | ||
// List all object paths in bucket my-bucketname. | ||
var objectsStream = s3Client.listObjects('my-bucketname', 'my-prefixname', true) | ||
objectsStream.on('data', function(obj) { | ||
objectsList.push(obj.name); | ||
}) | ||
objectsStream.on('error', function(e) { | ||
console.log(e); | ||
}) | ||
objectsStream.on('end', function() { | ||
s3Client.removeObjects('my-bucketname',objectsList, function(e) { | ||
if (e) { | ||
return console.log('Unable to remove Objects ',e) | ||
} | ||
console.log('Removed the objects successfully') | ||
}) | ||
}) | ||
``` | ||
<a name="removeIncompleteUpload"></a> | ||
@@ -630,0 +686,0 @@ ### removeIncompleteUpload(bucketName, objectName[, callback]) |
{ | ||
"name": "minio", | ||
"version": "5.0.2", | ||
"version": "6.0.0", | ||
"description": "S3 Compatible Cloud Storage client", | ||
@@ -11,3 +11,4 @@ "main": "./dist/main/minio.js", | ||
"functional": "gulp functional-test", | ||
"browserify": "gulp browserify" | ||
"browserify": "gulp browserify", | ||
"prepare": "npm run compile" | ||
}, | ||
@@ -41,2 +42,3 @@ "repository": { | ||
"mkdirp": "^0.5.1", | ||
"querystring": "0.2.0", | ||
"source-map-support": "^0.4.12", | ||
@@ -46,4 +48,3 @@ "through2": "^0.6.5", | ||
"xml": "^1.0.0", | ||
"xml2js": "^0.4.15", | ||
"querystring": "0.2.0" | ||
"xml2js": "^0.4.15" | ||
}, | ||
@@ -50,0 +51,0 @@ "devDependencies": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
554387
59
5020