【问题标题】:Image corrupted from s3从 s3 损坏的图像
【发布时间】:2020-12-19 02:44:41
【问题描述】:

这是我的上传代码(节点)

// generate a uuid string
            const uuid = uuidv4(); // type string

            // upload to wasabi

            fs.readFile(file.tempFilePath, "utf8", (err, data) => {
                if (err) {
                    throw (err);
                }
                // upload the object
                s3.upload(
                    {
                        Body: data,
                        Key: uuid + "-" + file.name,
                        Bucket: "files",
                        Metadata: { 'ext': ".png" },
                        // ContentLength: file.size
                    }, (err, data) => {
                        if (err) {
                            console.log(err);
                            throw (err);
                        }
                        console.log(data); 
                });
            });

对象实际上确实到达了存储桶。它有超过 0 个字节。它大约是源图像的一半,但我只是假设有人正在压缩它(芥末或其他东西)。 我正在使用 express-fileupload,我的配置是:


app.use(fileUpload({

    createParentPath: true,

    limits: {
        fileSize: 2 * 1024 * 1024 * 1024 //2MB max file(s) size
    },

    useTempFiles: true,

    tempFileDir: "/tmp/",

}));

最终我直接从芥末网络客户端下载了这个,并尝试在图像查看器中打开它,他们都说文件中有错误或者他们不支持文件类型(即 .png,所以支持)。 图像只有 ~150kb 。 基本上文件到达那里,但它已损坏。

【问题讨论】:

    标签: node.js amazon-s3 aws-sdk aws-sdk-nodejs wasabi-hot-cloud-storage


    【解决方案1】:

    utf8 是一种文本编码。但是.png 不是文本。只需删除编码选项,它应该可以工作。

    【讨论】:

    • 非常感谢,由于某种原因,其他答案成为了答案。我认为如果你从缓冲区中读取,你就会这样做。
    猜你喜欢
    • 2020-04-15
    • 2016-04-14
    • 2021-03-15
    • 2015-11-14
    • 2018-01-16
    • 2019-05-28
    • 2022-08-13
    • 1970-01-01
    相关资源
    最近更新 更多