我正在尝试从Floara编辑器上传图像到AWS S3,并使用angular io和nodejs框架。
Froala函数生成哈希/签名
var configs = {
bucket: 'web.document.images',
region: 'ap-south-1',
keyStart: 'image',
acl: 'public-read',
accessKey: "MyAWSaccessKey",
secretKey: "AWSsecretkey",
}
var s3Hash = FroalaEditor.S3.getHash(configs);
res.send(s3Hash);
CORS配置S3
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>http://localhost:3000</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>PUT</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>
下面是我得到的错误。 在控制台
POST https://s3-ap-south-1.amazonaws.com/web.document.images 400 (Bad Request)
并从“网络”标签中我可以预览为
<Error>
<Code>
InvalidArgument
</Code>
<Message>
Malformed Unicode code sequence in the field.
</Message>
<ArgumentName>
formField
</ArgumentName>
<RequestId>
B0525397B7A4F4BC
</RequestId>
<HostId> XixTwvJmFCNPaKNpkdquQ5/wAzacTC8LPpApEb7XAySQ4pL3AFM2V6XeacGpAZcAP5gepD3myMo=
</HostId>
</Error>
感谢任何帮助。
感谢。
答案 0 :(得分:0)
在froala编辑器初始化中删除以下参数后它正在工作,可能是因为在我的情况下我上传到S3,所以不需要这些参数。由于Froala知道我们上传图像的服务器(S3)(即支持的格式,方法等)
<script>
$(function() {
$('.selector')
.froalaeditor({
// Set the image upload parameter.
imageUploadParam: 'image_param',
// Additional upload params.
imageUploadParams: {id: 'my_editor'},
// Set request type.
imageUploadMethod: 'POST',
// Set max image size to 5MB.
imageMaxSize: 5 * 1024 * 1024,
// Allow to upload PNG and JPG.
imageAllowedTypes: ['jpeg', 'jpg', 'png']
})