Git Product home page Git Product logo

Comments (3)

kyungilpark avatar kyungilpark commented on August 24, 2024 1

요청헤더에 file_name 이 포함되어있지 않아서 그런것 같습니다.
xhr 전송전에 아래와 같이 헤더 추가해보면 되지 않을까요?

	xhr.setRequestHeader("file-name",encodeURIComponent(tempFile.name));
	// 전송
	xhr.send(tempFile);
}

from smarteditor2.

jadding avatar jadding commented on August 24, 2024

답변주셔서 감사합니다. 말씀하신대로 추가했더니 저장은 되는데, 0kb로 빈 파일로 저장 됩니다;;

console.log로 responseText, xhr.readyState, xhr.status 찍어보면 '', 4, 200 나옵니다. 통신은 잘 되는 것 같지만 이미지는 정상적으로 저장이 되지 않아요.

그래서 //xhr.setRequestHeader("Content-Type", "multipart/form-data"); 함 추가해봤었는데, 크롬에서 CORS 발생하더라고요. 파일 자체도 아예 생성 되지 않습니다. (xhr.status: 0)

업로드가 참 .. 풀리지 않네요;;;

function callAjaxForHTML5 (tempFile, sUploadURL){
    	console.log('::callAjaxForHTML5::');
        // IE
        if (window.ActiveXObject)
            xhr = new ActiveXObject("Microsoft.XMLHTTP");
        // Others
        else
            xhr = new XMLHttpRequest();


	xhr.open("POST", sUploadURL, true); //sUploadURL::https://도메인/test/smarteditor2-2.8.2.3/sample/photo_uploader/file_uploader_html5.php
	xhr.withCredentials = true;
       //xhr.setRequestHeader("Content-Type", "multipart/form-data");
        xhr.onreadystatechange = function() {
            var responseText = xhr.responseText;

            console.log('responseText ::' +responseText);
            console.log('readyState ::' +xhr.readyState);
            console.log('xhr.status ::' +xhr.status);
            if (xhr.readyState == 4) {
                // HTTP Status - 성공
                if (xhr.status == 200) {
                	makeArrayFromString(responseText);
                }
                // HTTP Status - 실패
                else {
                    onAjaxError();
                }                
            }
        };

        // Timeout 처리
        xhr.timeout = 5000;
        xhr.ontimeout = function() {
            onAjaxError();
        };

        // Form 생성
        var form = new FormData();
        form.append("file_name", tempFile);

        // 전송
	xhr.setRequestHeader("file-name",encodeURIComponent(tempFile.name));
        xhr.send(form);
    }

빈파일로저장_hiworks_20230406_645

from smarteditor2.

kyungilpark avatar kyungilpark commented on August 24, 2024

혹시 1M 이하의 작은 사이즈이미지는 저장되나요?
만약 작은 사이즈이미지는 저장된다면 php 서버 설정값 문제일 수 있습니다.
https://stackoverflow.com/questions/21271687/file-get-contentsphp-input-returns-empty-string-with-large-files

from smarteditor2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.