To save a picture to a mobile photo album, you must download a download file to download the picture. The picture can be saved normally on IOS mobile phone, but it fails to save on an Android mobile phone
the returned address is of unknown type. At this time, saving will fail
Therefore, it is necessary to uni.download file ({filePath: wx.env.USER_ DATA_ PATH + ‘/ file.jpg ’})
add this code to change the address, and then it will be saved successfully
//Save images locally
savePoster(){
uni.showLoading({
title:'Downloading...'
})
uni.downloadFile({
url:this.playBillUrl,// This is the web image address that the backend gets
filePath: wx.env.USER_DATA_PATH + '/file.jpg',// This must be written here otherwise Android will download the address after it appears.unknown
success:res => {
uni.hideLoading()
if (res.statusCode === 200) {
uni.saveImageToPhotosAlbum({
filePath: res.filePath,
success: function() {
uni.showToast({
title:'save sucessfully'
})
},
fail: function(res) {
console.log(res)
uni.showToast({
title:'save failed, please try again later'
})
}
});
} else {
uni.showToast({
title:'Download error'
})
uni.hideLoading()
}
}
})
Read More:
- [Solved] Android app development version update failed, Android – error: task execution failed ‘: app: com
- JZVideo Error: Attempt to invoke virtual method ‘android.view.Window android.app.Activity.getWindow()’ on a null object reference
- [Solved] Android9.0 App Install Android4.4 Error: InflateException-You must supply a layout_height attribute.
- [Solved] Android 9.0 APP Install Android 4.4 Error: IllegalArgumentException
- Android7.0+ Failed to Share Images: exposed beyond app through ClipData.Item.getUri()
- [Solved] Android Project error: import android.support.v4 (V7). App.activitycompat
- [Solved] Error: Failed to download metadata for repo ‘docker-ce-stable‘: Cannot download repomd.xml:
- [Solved] Android Error: Execution failed for task ‘:app:mergeReleaseNativeLibs‘.
- Android studio Error:Execution failed for task ‘: app:transformResourcesWithMergeJavaResForDebug ‘
- [Solved] jink Download Error: Failed to download RAMCode. Failed to prepare for programming.
- [Solved] Android12 Download Error: The application could not be installed: INSTALL_PARSE_FAILED_MANIFEST_MALFORMED
- [Solved] STM32 Use DAP to Download Error: Error: Flash Download failed – “Cortex-M3“
- [Solved] Android Studio Compile Error: Execution failed for task ‘:APP_MIDI:lintVitalRelease‘.
- [How to Solve] canvas.save(Canvas.ALL_SAVE_FLAG)
- [Solved] Android Studio Error: Error:Execution failed for task’:app:mergeDebugResources’
- ST-LINK Download Program Error: flash download failed – ‘cortex m4‘
- [Solved] stm32 Failed to Download: Error: Flash Download failed – “Cortex-M3”
- [Solved] :app:processDebugResources Android resource linking failed Android resource linking failed
- Remember an android app startup error Error running: Default Activity not found
- [Solved] Ubuntu uses gym to save the video error: “unknown encoder ‘libx264′”