file-cloud-storage
Advanced tools
Comparing version 1.1.0 to 1.2.0
{ | ||
"name": "file-cloud-storage", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "A set of wrappers for S3 clients", | ||
@@ -27,2 +27,3 @@ "keywords": [ | ||
"s3:upload": "node ./examples/upload.js", | ||
"s3:upload-binary": "node ./examples/upload-binary.js", | ||
"s3:upload-multipart": "node ./examples/upload-multipart.js" | ||
@@ -32,4 +33,5 @@ }, | ||
"async": "^3.2.0", | ||
"ibm-cos-sdk": "^1.7.0" | ||
"ibm-cos-sdk": "^1.7.0", | ||
"mime-types": "^2.1.27" | ||
} | ||
} |
@@ -17,3 +17,3 @@ # File Cloud Storage | ||
const { getContent, uploadText } = getS3Client('ibm', { | ||
const { getContent, uploadBinary, uploadMultiPartFile, uploadText } = getS3Client('ibm', { | ||
endpoint: '<endpoint>', | ||
@@ -29,2 +29,4 @@ apiKeyId: '<apiKey>', | ||
try { | ||
await uploadBinary(bucket, 'test.mp3', 'test.mp3'); | ||
await uploadMultiPartFile(bucket, 'test.avi', 'test.avi'); | ||
await uploadText(bucket, fileName, 'test content'); | ||
@@ -31,0 +33,0 @@ const fileContent = await getContent(bucket, fileName); |
const { S3 } = require('ibm-cos-sdk'); | ||
const fs = require('fs'); | ||
const mime = require('mime-types'); | ||
const timesSeries = require('async/timesSeries'); | ||
const readFile = require('./read-file'); | ||
module.exports = (credentials) => { | ||
@@ -25,2 +28,14 @@ const s3Client = new S3(credentials); | ||
}, | ||
uploadFile(bucketName, fileName, filePath) { | ||
return new Promise((resolve, reject) => { | ||
readFile(filePath) | ||
.catch((err) => reject(err)) | ||
.then((fileText) => s3Client.putObject({ | ||
Bucket: bucketName, | ||
Key: fileName, | ||
Body: fileText, | ||
ContentType: mime.contentType(filePath) || 'application/octet-stream', | ||
}).promise().then(resolve).catch(reject)); | ||
}); | ||
}, | ||
uploadMultiPartFile(bucketName, fileName, filePath) { | ||
@@ -27,0 +42,0 @@ return new Promise((resolve, reject) => { |
Sorry, the diff of this file is not supported yet
156540
12
139
38
3
2
+ Addedmime-types@^2.1.27
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)