我正在构建一个 HTML/JS 应用程序,我将其构建到 PhoneGap IOS/Android 应用程序中,以帮助 friend 在她的智能手机上填写调查表格,将其存储在手机上,然后在需要时将其上传到服务器她获得了 3G 覆盖。
我现在的问题是我想将照片附加到这些表格中。我的计划是使用jquery序列化文件的路径,将其存储在localstorage中,然后通过ajax上传。但这似乎不起作用。
有什么方法可以存储图像的路径,然后仍然可以上传吗?或者我是否必须以某种方式存储整个文件?
最佳答案
来自 Phonegap 文档:
navigator.camera.getPicture( cameraSuccess, cameraError, [ cameraOptions ] );
The return value will be sent to the cameraSuccess function, in one of the following formats, depending on the cameraOptions you specify:
A String containing the Base64 encoded photo image.
A String representing the image file location on local storage (default).
将 base64 放入本地存储并在上传时获取它会更简单,但如果您愿意,您应该能够存储路径,然后从中检索数据并在有连接时上传。
[编辑]
我没有考虑@jaay 在评论中指出的问题。如果文件稍后更改怎么办?也许存储 Base64 数据会更好。
关于javascript - 将文件路径/图像存储在智能手机本地并稍后上传?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17190672/