|
本帖最后由 kisshexuxia 于 2016-6-2 14:52 编辑
看了http://bbs.wex5.com/forum.php?mod=viewthread&tid=91095&extra=&page=1
文章想是不是可以上传语音文件然后找到了DEMO $UI/demo/native/audio/
现在碰到如下问题首先上面照片引用的codova插件返回的就是base64加密的navigator.camera.getPicture
但是语音这边没有加密、所以我想实现语音base64加密
- self.uploadVoice(Base64.encode(this.mediaRec));
复制代码 我在手机上测试这个代码报base64.encode(this.mediaRec)
这样写是不行的。不知道要怎么写才能对刚才录制的语音文件加密
在停止录音新增代码
- //停止播放、停止录音
- Model.prototype.pauseImageClick = function(event){
- // 清空计时器
- var self = this;
- clearInterval(this.mediaTimer);
- if (this.operateType == "record") {
- // 停止录音
- this.comp("recordCover").hide();
- this.mediaRec.stopRecord();
-
- var data = this.comp("fileData");
- data.newData({index : 0});
- data.setValue("fileName", this.fileName);
- data.setValue("createTime", justep.Date.toString(new Date(), justep.Date.DEFAULT_FORMAT))// 开始时间
- data.setValue("timeLen", this.timeLen);// 录音时长
- <font color="Red">self.uploadVoice(Base64.encode(this.mediaRec)); </font>
- this.comp('fileOutput').set({value: "音频文件名"+this.fileName});
- }else{
- //停止播放
- this.comp("playCover").hide();
- this.mediaRec.stop();
- }
- };
复制代码
- //调用bass实现语音上传
- Model.prototype.uploadVoice = function(VoiceData){
- var userid = 'aaa';
- var storeFileName = "";
- var imageJson = {};
- storeFileName = justep.UUID.createUUID();
- // alert(imageData);
- justep.Baas.sendRequest({
- "url" : "/ymf/ymftest", //baas目录,请根据自己的配置进行修改
- "action" : "uploadVoice",
- "async" : false,
- "params" : {
- "picData" : VoiceData,
- "ownerID" : userid,
- "storeFileName" : storeFileName
- },
- "success" : function(data) {
- justep.Util.hint("语音上传成功");
- }
- });
- };
-
复制代码
baas代码
- //上传语音
- public static JSONObject uploadVoice(JSONObject params, ActionContext context) throws SQLException, NamingException, IOException {
- System.out.println("uploadPicfile is running...");
- String ownerID = params.getString("ownerID");
- String storeFileName = params.getString("storeFileName");
- String picData = params.getString("picData");
- String baasPath = Thread.currentThread().getContextClassLoader().getResource("").getPath();
- String docStorePath = baasPath + ".." + File.separator + ".." + File.separator + "model" + File.separator + "UI2" + File.separator + "ymfTest15" + File.separator + "uploadfiles";
- File docstoreDir = new File(docStorePath);
- if (!(docstoreDir.exists() && docstoreDir.isDirectory())) {
- docstoreDir.mkdirs();
- }
- String storePath = docStorePath + File.separator + ownerID;
- File storeDir = new File(storePath);
- if (!(storeDir.exists() && storeDir.isDirectory())) {
- storeDir.mkdirs();
- }
- System.out.println("后台计算的baasPath的值:" + baasPath);
- System.out.println("后台计算的docStorePath的值:" + docStorePath);
- System.out.println("后台计算的storeDir的值:" + storeDir);
- BASE64Decoder decoder = new BASE64Decoder();
- try {
- byte[] decodedBytes = decoder.decodeBuffer(picData);
- String imgFile = storePath + File.separator + storeFileName;
- FileOutputStream out = new FileOutputStream(imgFile);
- out.write(decodedBytes);
- out.close();
- System.out.println("语音上传成功!");
- } catch (Exception e) {
- System.out.println("语音上传失败!");
- e.printStackTrace();
- }
- return null;
- }
-
复制代码
|
|