In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article shows you Java WeChat Mini Programs oss picture upload method is what, the content is concise and easy to understand, absolutely can make your eyes bright, through the detailed introduction of this article hope you can get something.
First upload the picture to the server, and then transfer the picture from the server to the oss
Mini Program js
/ / waiting to start upload. Wx.showToast ({title: 'uploading...', icon: 'loading', mask: true, duration: 10000}) / / upload image wx.uploadFile ({url:' *', / / upload path (Java backend path) filePath: tempFilePaths [0], name: 'file', success: function (res) {console.log (res.data) / / oss image path wx.showToast ({title: "upload successfully") Icon: 'success', duration: 1000})}, fail: function ({errMsg}) {wx.showToast ({title: "upload failed", duration: 1000})},})
Java background
@ RequestMapping ("/ programImg") public @ ResponseBody String programImg (@ RequestParam (required = false) MultipartFile file,HttpServletRequest request) {File targetFile=null; String str= "; / / return the storage path String fileName=file.getOriginalFilename (); / / get the file name with the suffix if (fileNameplate name =") {String returnUrl =" * "; / / server storage path String fileF = FilenameUtils.getExtension (file.getOriginalFilename ()) / / File suffix fileName= "*"; / / New file name / / determine whether the file exists first and get the folder path File file1 = new File (returnUrl); / / if the folder does not exist, create if (! file1 .folder () & &! file1 .isDirectory ()) {file1 .mkdir ();} / / save the picture in the folder targetFile = new File (file1, fileName) Try {/ / writes the uploaded file to the file specified on the server. File.transferTo (targetFile); String gifName = "*"; / / Image oss upload root directory String url=gifName+ "/" + fileName; putObject (targetFile, gifName,fileName); str= ""; / / oss Image path} catch (Exception e) {e.printStackTrace ();}} return str;} public static void putObject (File file,String fileName,String fileName) {OSSClient ossClient=null; try {/ / initialize oss ossClient= ossIni (); / / upload path String route=fileName+ "/" + fileName / / upload picture img-program--Bucket name ossClient.putObject ("img-program", route,file);} catch (Exception e) {if (osClientclimate null) {ossClient.shutdown ();} e.printStackTrace ();} ossClient.shutdown ();} private static OSSClient ossIni () {OSSClient ossClient = null; try {ossClient = new OSSClient (ENDPOINT,KEY_ID,KEY_SECRET); System.out.println ("oss initialization successful");} catch (Exception e) {e.printStackTrace () } return ossClient;} public static final String ENDPOINT= "*"; public static final String KEY_ID= "*"; public static final String KEY_SECRET= "*"
The above content is what is the implementation of Java WeChat Mini Programs oss picture upload? have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.