How to handle true string data in javascript
How to handle true string data in javascript
I have controller method and javascript method for recording audio.
Controller:
This controller will return string data
@RequestMapping(value = "/sendAudioBlobData/{questionId}", headers = "content-type=multipart/*", method = { RequestMethod.GET, RequestMethod.POST })
@ResponseBody
public String getBlob(HttpServletRequest request,HttpServletResponse response, ModelMap model, @RequestParam(value = "file") MultipartFile file, @PathVariable(value = "questionId") int questionId) {
boolean flag = false;
String id = Integer.toString(questionId);
String fileName = null;
byte[] bytes;
try {
bytes = file.getBytes();
if (!file.isEmpty()) {
id = id + ".mp3";
fileName = VOPortalConstants.NLE_USER_AUDIO_FILES_ROOT + File.separator + id;
BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream(new File(fileName)));
stream.write(bytes);
stream.close();
File f = new File(fileName);
if(f.exists()) {
response.addHeader("Content-Length", f.length() + "");
FileUtils.sendFile(f, response.getOutputStream());
}
}
}
catch (IOException e) {
logger.error("ERROR: ", e);
}
String fName = fileName.replace(VOPortalConstants.NLE_PATH, VOPortalConstants.NLE_URL_CONST);
return fName;
}
JS Method:
This code provide that to request(POST) for recording user's audio
function saveAudioFile() {
var questionId = window.questionList[window.counter].id;
recorder && recorder.exportWAV(function(blob) {
var formData = new FormData();
formData.append("file", blob);
$.ajax({
url : "sendAudioBlobData/" + questionId,
type: 'POST',
data: formData,
dataType: "text",
contentType: false,
processData: false,
success: function(data) {
debugger
var audio = $("#your_voice");
$("#your_voice_source").attr("src", data);
/****************/
audio[0].pause();
audio[0].load();//suspends and restores all audio element
//audio[0].play();
/****************/
},
error: function() {
alert("not so boa!");
}
});
});
}
in controller, return value is string that looks as follows -> fName=/NLERESOURCES/NLE/VOICE/USERVOICE'107.mp3
but return data that looks as follows in js -> RIFF$@WAVEfmt��������������������������������������������������������������������������������������������������������������������������������
how i do handle true string data?
Thanks
FileUtils.sendFile is returning the file as part of the Response outputstream from the controller.
相关文章:
- Node.js's Buffer.writeFloatBE in Javascript
- Ember Data DS.Model's set函数不起作用
- Extending Ext.data.NodeInterface
- Setting default onclick behavior for <img> tag in gene
- Lucene Search in Alfresco
- 如何获取$data.Entity的密钥
- grep in JQuery to C#
- jQuery可以't获取data-*属性值,返回undefined
- Query JS Ext.data.Store
- jquery .data() in javascript
- data-rel in .attr (javascript)
- showing data in angular
- Google Chart (Material) - Type Bar - Data in arrayToDataTabl
- What does 'data()' do in '$("#myWidget"
- knockout js data-bind child in object
- SugarCRM: Putting a image data type in 'Cases' modul
- 如何使用Promise in Service AngularJS?示例Data Firebase
- 使用ng-bind时更新data in指令
- How to handle true string data in javascript
- increment/decrement .data() in jQuery