2014-09-29 6 views
1

모두. 불행하게도 멋진 JSZIP 라이브러리를 사용하여 zip 파일에 mp3를 추가하려고합니다. 지금은 올바른 파일 이름으로 zip 파일을 만들었지 만 mp3은 항상 비어 있습니다.jszip을 사용하여 zip에 mp3를 추가

//init 
var zip = new JSZip(); 

//add an mp3 titled "any other way" and decode binary to base64 
zip.file("any other way.mp3", btoa("absolutepath/to/my/file/any_other_way.mp3"), {base64: true}); 

//generate zip 
var content = zip.generate(); 

//download zip 
location.href="data:application/zip;base64,"+content; 
+1

은 다음과 같습니다

// loading a file and add it in a zip file JSZipUtils.getBinaryContent("path/to/audio.mp3", function (err, data) { if(err) { throw err; // or handle the error } var zip = new JSZip(); zip.file("audio.mp3", data, {binary:true}); }); 
또한

http://stuk.github.io/jszip-utils/documentation/api/getbinarycontent.html

은, 여기 문제에 대한 링크입니다 : 당신이 IE에서 작동하도록 원하는 사파리 경우, 당신은 Downloadify (http://stuk.github.io/jszip/documentation/howto/write_zip.html#toc_3)를 구현해야합니다 당신은 확실히 PC에서 파일을 가져 와서 그것을 인코딩합니까? 내가 아는 한, 문자열 매개 변수 만 인코딩합니다. 실제 파일 내용을 가져 오려면 파일 입력을 사용해야합니다. https://developer.mozilla.org/en-US/docs/Using_files_from_web_applications – Luizgrs

+0

이런, 그럴 수도 있습니다. 그것이 효과가 있었는지 알려줄 것입니다. –

답변