근 두달만에 겨우 해결했네..

키워드를 잘 못 잡았던 걸까 싶긴한데

아무튼.. FileList() 객체로 생성되고 그랬던 거라.. 

File() 객체를 생성하는걸 생각 못한게 2달 날린(?) 원인.. ㅠㅠ



+

new File() 에는 Array가 첫번째 인자인걸 주의!!!!

(망할!!!!!)


var blobdata = document
.getElementById("target_obj_cnv")
.toDataURL("image/png");
blobdata = dataURLtoBlob(blobdata);
var imgFile2 = new File([blobToFile(blobdata, "target.png")], "target.png");
var data = new FormData();

data.append("image", imgFile2);

[링크 : https://stackoverflow.com/questions/27251953/how-to-create-file-object-from-blob[

[링크 : https://developer.mozilla.org/en-US/docs/Web/API/File/File]



+

걍 포기해야 하나? ㅠㅠ

[링크 : https://stackoverflow.com/questions/38449440/javascript-create-file-list-object-from-list-of-files]

[링크 : https://developer.mozilla.org/en-US/docs/Web/API/FileList]


+

으으.. 영 안되네.. ㅠㅠ


function blobToFile(theBlob, fileName) {
var date = new Date();
theBlob.lastModifiedDate = date;
theBlob.lastModified = date.getTime();
theBlob.name = fileName;
return theBlob;
}

function dataURLtoBlob(dataurl) {
var arr = dataurl.split(","),
mime = arr[0].match(/:(.*?);/)[1],
bstr = atob(arr[1]),
n = bstr.length,
u8arr = new Uint8Array(n);
while (n--) {
u8arr[n] = bstr.charCodeAt(n);
}
return new Blob([u8arr], { type: mime });

} 

var blobdata = document
.getElementById("cnv")
.toDataURL("image/png");
blobdata = dataURLtoBlob(blobdata);
var imgFile2 = blobToFile(blobdata, "target.png");


[링크 : https://stackoverflow.com/questions/6850276/how-to-convert-dataurl-to-file-object-in-javascript]


+

Vanilla JavaScript


function blobToFile(theBlob, fileName){

    //A Blob() is almost a File() - it's just missing the two properties below which we will add

    theBlob.lastModifiedDate = new Date();

    theBlob.name = fileName;

    return theBlob;

[링크 : https://stackoverflow.com/questions/27159179/how-to-convert-blob-to-file-in-javascript/29390393]



---

[링크 : https://code.i-harness.com/ko-kr/q/4c46fc]


[링크 : https://teamtreehouse.com/community/how-to-create-a-file-from-a-dataurl-javascript]


var dataurl = canvas.toDataURL('image/jpeg',0.8);

var blob = dataURLtoBlob(dataurl);

var fd = new FormData();

fd.append("myFile", blob, "thumb.jpg"); 

[링크 : https://stackoverflow.com/questions/4998908/convert-data-uri-to-file-then-append-to-formdata]

[링크 : https://stackoverflow.com/questions/15675063/how-to-create-an-image-file-on-server-from-dataurl]

'Programming > javascript & HTML' 카테고리의 다른 글

ajax success 콜백 사용하기  (0) 2018.12.15
js __proto__  (0) 2018.12.14
canvas dataURL to Formdata(file)  (0) 2018.12.07
js 부모창 변수 접근하기  (0) 2018.12.04
크로스 브라우징 관련..  (0) 2018.11.30
wavesurfer.js HTML5 AUDIO 미지원시  (0) 2018.11.30
Posted by 구차니

댓글을 달아 주세요