base64 映像已损坏上传到 S3
base64 image corrupted uploading to S3
router.post('/image', multipartMiddleware , function(req, res) {
var file_name = req.body.name;
var data = req.body.data;
return s3fsImpl.writeFile(file_name , data , 'base64').then(function (err) {
res.status(200).end();
});
});
我上面的代码出了什么问题?我的热中没有错误,我的 s3 中有该文件,但下载时它已损坏。
由于我不知道您的代码中s3fsImpl
是什么,因此我无法回答您的实现,但这是我使用 aws-sdk 的方法:
const AWS = require('aws-sdk');
const s3 = new AWS.S3({apiVersion: '2006-03-01'});
const file_name = req.body.name;
const data = req.body.data;
// We need to get the format of the file from the base64 string i.e. data:image/png;base64<base64String>
const format = data.substring(data.indexOf('data:')+5, data.indexOf(';base64'));
// We need to get the actual file data from the string without the base64 prefix
const base64String = data.replace(/^data:image'/'w+;base64,/, '');
const buff = new Buffer(base64String,'base64');
s3.upload({
Bucket:'s3-bucket-name',
Key: file_name,
Body: buff,
ContentEncoding:'base64',
ContentType:format
}, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
相关文章:
- 如何使jQuery中的悬停函数单独应用于数据库映像
- 无法在Safari中加载跨源映像(来自CloudFront)
- 有没有一种方法可以从chrome'的存储映像
- 如何在不必维护每个文件的两个版本的情况下,将通用JavaScript和映像部署到两个不同的EAR
- 在使用 Django 静态文件时动态设置映像时,只有绝对路径才能与 jquery 一起使用
- 获取我的数组中的每个 ID 映像 src
- 映像选取器在初始化时预选项
- 循环映像 IE7 问题
- 本地映像对象未在Javascript中正确初始化
- PHP抓取没有扩展的远程映像
- 如何在ASP.NET Response.BinaryWrite生成的Javascript中处理字节数组映像
- JQuery Error在出现错误时加载备用映像的事件
- 要映像的 Blob URL
- 如何为 Amazon S3 中存储的每个映像分配默认目录
- Cant 使用 awssum 和 nodejs 将映像保存到 Amazon S3
- 对下载的 S3 映像的 URI 进行编码
- 找不到Amazon S3映像.不得不拖延
- base64 映像已损坏上传到 S3
- 将映像(base64)保存到s3而不是数据库
- 来自S3的映像不能与Service Worker一起工作