我正在尝试使用ng-file-upload将文件上传到我的服务器,同时调整大小并将其转换为客户端的png . 从文档中可以看出,这可以使用 ngf-resize
属性并将 type
属性设置为 image/png
.
这里的文档:https://github.com/danialfarid/ng-file-upload/blob/master/README.md描述 type
as:"type is optional convert it to the given image type format."
当我尝试这个时,它适用于png源文件,但是如果我使用jpg文件它不会将其转换为png,而是在Javascript控制台中出现此错误:
There were invalid base64 characters in the input text.
Valid base64 characters are A-Z, a-z, 0-9, NaNExpect errors in decoding.
这是我的代码:
<div ngf-drop ngf-select ng-model="file" class="drop-box"
ngf-drag-over-class="'dragover'" ngf-multiple="false"
ngf-allow-dir="false" accept="image/jpeg,image/jpg,image/png"
ngf-pattern="'image/jpeg,image/jpg,image/png'"
ngf-resize="{width: 100, height: 100, quality: .8, centerCrop: true, type: 'image/png'}">
甚至可以使用ng-file-upload将jpg转换为png吗?或者我有代码问题?我的目标是让浏览器进行转换,以便我的服务器只接收png图像 .
1 回答
问题是该插件正在尝试恢复png文件中的exif数据,因为它不是jpeg会失败 . 为了避免这种情况你可以: