Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm currently trying to upload an image to a S3 bucket (digitalocean spaces). I found some information on using multer and multer s3 on the digitalocean spaces page, but they used express js to use a post request to send the file.

I tried to use a meteor method to send an image to the server and use multer to store it in s3.

The following code is used on the client side to capture the image and to send it to the server side:

'click #takePhoto': (event, template) => {
        canvas.width = video.videoWidth;
        canvas.height = video.videoHeight;
        canvas.getContext('2d').drawImage(video, 0, 0);
        const data = canvas.toDataURL('image/jpeg');
        document.getElementById('photo').setAttribute('src', data);
        // Meteor call to send the canvas to the server for storing on s3
        Meteor.call('uploadPicture', data, template.data);
}

On the server side I'm using the following code to connect to the s3 and where I tried to upload the file to mul

const spacesEndpoint = new AWS.Endpoint('ams3.digitaloceanspaces.com');
const s3 = new AWS.S3({
    endpoint: spacesEndpoint,
    accessKeyId: Meteor.settings.private.digitalOceanSpaces.accessKeyId,
    secretAccessKey: Meteor.settings.private.digitalOceanSpaces.secretAccessKey
});

var upload = multer({
    storage: multerS3({
        s3: s3,
        bucket: 'test-bucket'
        metadata: function (req, file, cb) {
            cb(null, { fieldName: file.fieldname });
        },
        key: function (req, file, cb) {
            cb(null, Date.now().toString())
        }
    })
})

upload.single(picture);

Where picture at the final upload is from the canvas.toDataURL('image/jpeg') function that gets send to the server.

When I now run this function it doesn't give me an error but it also doesn't appear on the spaces, so it's not sending it correctly.

I would like to hear if someone was able to get this working or if they have used different solutions for uploading images to a s3 storage. I also couldn't figure out where I could catch an error somewhere here to get some more debugging info where it is giving me an issue.

Thank you in advance!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
444 views
Welcome To Ask or Share your Answers For Others

1 Answer

等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...