2017-05-04 20 views
7

Dosyaları aws sunucusuna yüklemek için nodejs kullanıyorum. ve dosya boyutunun uygun şekilde bulunamadı. 2,1KB alıyorum. benim aws kovada dosya adı var, her ne kadarStreaming-s3, düzgün bir şekilde aws dosyasına dosyalamıyor

burada benim kod

var uploadFile = function (fileReadStream, awsHeader, cb) { 

    //set options for the streaming module 
    var options = { 
     concurrentParts: 2, 
     waitTime: 20000, 
     retries: 2, 
     maxPartSize: 10 * 1024 * 1024 
    }; 
    //call stream function to upload the file to s3 
    var uploader = new streamingS3(fileReadStream, config.aws.accessKey, config.aws.secretKey, awsHeader, options); 
    //start uploading 
    uploader.begin();// important if callback not provided. 

    // handle these functions 
    uploader.on('data', function (bytesRead) { 
     //console.log(bytesRead, ' bytes read.'); 
    }); 

    uploader.on('part', function (number) { 
     //console.log('Part ', number, ' uploaded.'); 
    }); 

    // All parts uploaded, but upload not yet acknowledged. 
    uploader.on('uploaded', function (stats) { 
     //console.log('Upload stats: ', stats); 
    }); 

    uploader.on('finished', function (response, stats) { 
     console.log(response); 
     cb(null, response); 
    }); 

    uploader.on('error', function (err) { 
     console.log('Upload error: ', err); 
     cb(err); 
    }); 

}; 

olduğunu. ama sonra başarısız olduğunu söylediğim dosyayı açmaya çalışıyorum. Ben url Bu dosyayı yüklemeye çalışıyorum

: https://arxiv.org/pdf/1701.00003.pdf

herhangi bir öneriniz lütfen?

sayesinde s3 Akışları yüklemek için harici bir modül için artık gerek yoktur

cevap

2

. Artık rasgele boyutlu bir arabellek, blob veya akış yükleyebilen s3.upload adında aws-sdk'de yeni bir yöntem var. burada benim açımdan daha da Ben senin soru yayınlanmıştır pdf ile kod çalıştı kanıtlamak için

const aws = require('aws-sdk'); 
 
const s3 = new aws.S3({ 
 
    credentials:{ 
 
     accessKeyId: "ACCESS_KEY", 
 
     secretAccessKey: "SECRET_ACCESS_KEY" 
 
    } 
 
}); 
 
const fs = require('fs'); 
 
const got = require('got'); 
 

 
//fs stream test 
 
s3.upload({ 
 
    Bucket: "BUCKET_NAME", 
 
    Key: "FILE_NAME", 
 
    ContentType: 'text/plain', 
 
    Body: fs.createReadStream('SOME_FILE') 
 
}) 
 
.on("httpUploadProgress", progress => console.log(progress)) 
 
.send((err,resp) => { 
 
    if(err) return console.error(err); 
 
    console.log(resp); 
 
}) 
 

 

 
//http stream test 
 
s3.upload({ 
 
    Bucket: "BUCKET_NAME", 
 
    Key: "FILE_NAME", 
 
    ContentType: 'application/pdf', 
 
    Body: got.stream('https://arxiv.org/pdf/1701.00003.pdf') 
 
}) 
 
.on("httpUploadProgress", progress => console.log(progress)) 
 
.send((err,resp) => { 
 
    if(err) return console.error(err); 
 
    console.log(resp); 
 
})

ve: Sen here

kullandığım kod belgelerine kontrol edebilirsiniz link, test paketim için pdf'nin beklendiği gibi çalıştığını gösteriyor.

+0

: - Yukarıdaki kodda yalnızca yukarıdaki kodu kullanarak sorun yaşıyorum. Şimdi proje tamamlandı kodu değiştirmek için bir nokta yok –

+0

Yukarıdaki kodda sorunun ne olduğunu söyleyebilir misiniz? –

İlgili konular