Every line of 's3 createreadstream' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.
62 createReadStream(location, options) { 63 const client = this[scope].client 64 65 return client.file(location).createReadStream(options) 66 }
Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code
43 export function getObject (s3, params) { 44 return s3.getObject(params).promise(); 45 };
11 public async getObject(key: string, bucket: string) { 12 const params: S3.Types.GetObjectRequest = { 13 Bucket: bucket, 14 Key: key, 15 }; 16 return await this.s3 17 .getObject(params) 18 .promise() 19 .then((data: S3.Types.GetObjectOutput) => data) 20 .catch<null>(err => { 21 Utils.logError('S3 Get Object', err, params); 22 return null; 23 }); 24 }
23 function getS3(key) { 24 return new Promise((resolve, reject) => { 25 s3.getObject({ Bucket: process.env.BUCKET, Key: key }, (err, data) => { 26 if (err && err.code == 'NotFound') return reject(Errors.NOT_FOUND); 27 else if (err) { 28 const e = Object.assign({}, Errors.SOMETHING_WRONG, { err }); 29 return reject(e); 30 } 31 const content_type = data.ContentType; 32 const image = new Buffer(data.Body).toString('base64'); 33 return resolve({ 34 statusCode: 200, 35 headers: { 'Content-Type': content_type }, 36 body: image, 37 isBase64Encoded: true, 38 }); 39 }); 40 }); 41 }
313 createReadStream(key, callback) { 314 this._getSbucketForKey(key, (err, sBucket) => { 315 if (err) { 316 return callback(err); 317 } 318 319 callback(null, sBucket.createReadStream(key)); 320 }); 321 }
153 async put(stream, size, keyContext, reqUids, callback) { 154 const log = createLogger(reqUids); 155 let err = null; 156 let final_result = []; 157 try { 158 await set_auth_and_bucket_id_once(this); 159 let result = await get_upload_url(this.auth, this.bucketId); 160 let fileName = keyContext.objectKey; 161 let hashedStream = new SHA1Sum(); 162 stream.pipe(hashedStream); 163 // When sending the SHA1 checksum at the end, 164 // size should size of the file plus the 40 bytes of hex checksum. 165 result = await upload_file(result, hashedStream, fileName, size + 40) 166 final_result = [fileName, result.fileId]; 167 } catch (e) { 168 err = e; 169 logHelper(log, 'error', 'err from data backend', 170 err, this._dataStoreName); 171 } finally { 172 callback(err, final_result[0], final_result[1]); 173 } 174 }
92 function uploadSuperFile(client, bucketName, key, blob, options) { 93 if (!options['Content-Type']) { 94 var ext = key.split(/\./g).pop(); 95 // Firefox在POST的时候,Content-Type 一定会有Charset的,因此 96 // 这里不管3721,都加上. 97 var mimeType = sdk.MimeType.guess(ext) + '; charset=UTF-8'; 98 u.extend(options, { 99 'Content-Type': mimeType 100 }); 101 } 102 103 var uploadId = null; 104 return client.initiateMultipartUpload(bucketName, key, options) 105 .then(function (response) { 106 uploadId = response.body.uploadId; 107 108 var deferred = sdk.Q.defer(); 109 var tasks = getTasks(blob, uploadId, bucketName, key); 110 var state = { 111 lengthComputable: true, 112 loaded: 0, 113 total: tasks.length 114 }; 115 async.mapLimit(tasks, config.kParallel, uploadPartFile(state, client), function (err, results) { 116 if (err) { 117 deferred.reject(err); 118 } 119 else { 120 deferred.resolve(results); 121 } 122 }); 123 return deferred.promise; 124 }) 125 .then(function (allResponse) { 126 var partList = []; 127 allResponse.forEach(function (response, index) { 128 partList.push({ 129 partNumber: index + 1, 130 eTag: response.http_headers.etag 131 }); 132 }); 133 134 return client.completeMultipartUpload(bucketName, key, uploadId, partList); 135 }); 136 }
54 public async get(key: string): Promise<string|null> { 55 try { 56 let params = { 57 Bucket: this.bucket, 58 Key: key 59 }; 60 return (await this.client.getObject(params).promise() as LooseObject).Body.toString(); 61 } catch (e) {} 62 63 return null; 64 }
84 uploadFile (fileKey, fileStream, uploadOptions) { 85 const uploadFileKey = fileKey.replace(this.options.fullAssetPath, '').replace(/\\/g, '/') 86 const fullFileKey = `${this.options.deployPath}${uploadFileKey}` 87 88 const uploadParams = { 89 Bucket: this.name, 90 Key: fullFileKey, 91 Body: fileStream, 92 ContentType: this.contentTypeFor(fileKey) 93 } 94 95 if (uploadOptions.acl !== 'none') { 96 uploadParams.ACL = this.options.acl 97 } 98 99 if (uploadOptions.pwa) { 100 uploadParams.CacheControl = 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0' 101 } else { 102 uploadParams.CacheControl = this.options.cacheControl 103 } 104 105 if (uploadOptions.gzip) { 106 uploadParams.ContentEncoding = 'gzip' 107 } 108 109 return this.connection.upload( 110 uploadParams, 111 { partSize: (5 * 1024 * 1024), queueSize: 4 } 112 ).promise() 113 }
265 _uploadPart(metadata, read_stream, current_part_number) { 266 return this.client 267 .uploadPart({ 268 Bucket: this.bucket_name, 269 Key: metadata.file.id, 270 UploadId: metadata.upload_id, 271 PartNumber: current_part_number, 272 Body: read_stream, 273 }) 274 .promise() 275 .then((data) => { 276 log(`[${metadata.file.id}] finished uploading part #${current_part_number}`); 277 278 return data.ETag; 279 }) 280 .catch((err) => { 281 throw err; 282 }); 283 }