我编写了一个代码,用于从库中选择一个图像,并在本地将其显示为标记,并将其base64表单上传到服务器。
它在Android平台上运行得很好,但在iOS中存在问题。
有两件事:
1-我得到了类似
的路径file:///var/mobile/Containers/Data/Application/[some string]/tmp/[a name].jpg
2-并且标签已经配置为允许"文件" s
我感谢任何有用的指南。
答案 0 :(得分:2)
如果您使用的是cordova-plugin-image-picker
,则可以设置选项outputType: 1
。这将以base64格式返回图像。
来自plugin存储库:
options = {
// Android only. Max images to be selected, defaults to 15. If this is set to 1, upon
// selection of a single image, the plugin will return it.
maximumImagesCount: int,
// max width and height to allow the images to be. Will keep aspect
// ratio no matter what. So if both are 800, the returned image
// will be at most 800 pixels wide and 800 pixels tall. If the width is
// 800 and height 0 the image will be 800 pixels wide if the source
// is at least that wide.
width: int,
height: int,
// quality of resized image, defaults to 100
quality: int (0-100),
// output type, defaults to FILE_URIs.
// available options are
// window.imagePicker.OutputType.FILE_URI (0) or
// window.imagePicker.OutputType.BASE64_STRING (1)
outputType: int
};
请记住在返回的字符串之前添加data:image/jpeg;base64,
。
然后,例如:
this.imagePicker.getPictures({
maximumImagesCount: 1,
width: 800,
height: 800,
quality: 70,
outputType: 1 }) //base64 output
.then((results) => {
return 'data:image/jpeg;base64,'+results[0];
});