6-1 百度BAE的使用

 

https://developer.baidu.com/

https://cloud.baidu.com/product/bae.html

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

阅读更多

百度bae文件读写

07-26

我目前在做一个企业微信的开发涉及到拍照,拍照时上传到腾讯的服务器,需要用返还的serverid去腾讯多媒体接口下载到自己服务器,我项目是部署到百度BAE上面,当我去下载文件的时候一直报错文件不存在rnrn这是我下载文件的代码rn/**rn * 获取媒体文件rn *rn * @param accessToken 接口访问凭证rn * @param mediaId 媒体文件idrn * @param savePath 文件在本地服务器上的存储路径rn * @param nameExt 文件后缀名rn * rn */rn public static String downloadMedia(String accessToken, String mediaId, String savePath, String nameExt, rnString storeId, int order) rn String filePath;rn // 拼接请求地址rn String requestUrl = "https://qyapi.weixin.qq.com/cgi-bin/media/get?access_token=ACCESS_TOKEN&media_id=MEDIA_ID";rn requestUrl = requestUrl.replace("ACCESS_TOKEN", accessToken).replace("MEDIA_ID", mediaId);rn try rn URL url = new URL(requestUrl);rn HttpURLConnection conn = (HttpURLConnection) url.openConnection();rn conn.setDoInput(true);rn conn.setRequestMethod("GET");rnrn if (!savePath.endsWith(File.separator)) rn savePath += File.separator;rn rn // 根据内容类型获取扩展名rn String contentType=conn.getHeaderField("Content-Type");rn String fileExt = DloadImgUtil.getFileexpandedName(contentType);rn // 将mediaId作为文件名rn String fileName=FormatUtil.getPicName("pic1",storeId+"","1",".jpg");rn filePath =new Date().getTime() + savePath + fileName;rn BufferedInputStream bis = new BufferedInputStream(conn.getInputStream());rn File file=new File("home/bae/",fileName);rn if (!file.exists()) rn file.mkdirs();rn rn FileOutputStream fos = new FileOutputStream(file);rn byte[] buf = new byte[8096];rn int size = 0;rn while ((size = bis.read(buf)) != -1)rn fos.write(buf, 0, size);rn fos.close();rn bis.close();rnrn conn.disconnect();rn String info = String.format("下载媒体文件成功,filePath=" + filePath);rn System.out.println(info);rn catch (Exception e) rn filePath = null;rn String error = String.format("下载媒体文件失败:%s", e);rn System.out.println(error);rn rn return filePath;rn rnrnrn这是报的错:java.io.FileNotFoundException: home/bae/pic1_0045149_20170726100509_1.jpg (No such file or directory)rn也判断了是否存在rn

没有更多推荐了,返回首页