1

Thank you for your viewing. I am making an app for business name cards on Parse.com. So I want to save image file from HTML input to Parse DB, but I get the following console error from yesterday.

XMLHttpRequest cannot load https://api.parse.com/1/1/files/photo.jpg. 
Response to preflight request doesn't pass access control
check: No 'Access-Control-Allow-Origin' header is present on the requested resource. 
Origin 'https://***.***' is therefore not allowed access.
The response had HTTP status code 404.

OPTIONS https://api.parse.com/1/1/files/photo.jpg
dispatch @ parse-latest.js:8552
ajax @ parse-latest.js:8554
saveFile @ parse-latest.js:2483
save @ parse-latest.js:2401
(anonymous function) @ parse-latest.js:4478
wrappedResolvedCallback @ parse-latest.js:5292
(anonymous function) @ parse-latest.js:5353
runLater @ parse-latest.js:5337
then @ parse-latest.js:5352
(anonymous function) @ parse-latest.js:4477
save @ parse-latest.js:4475
save @ parse-latest.js:3828
cardMake @ ***.html:119
onclick @ ***.html:184
***.html:1 

and here is my JS code.

        function cardMake(){
            var visualUpload = $("#inputVisual")[0];
            var inputVisualFile = visualUpload.files[0];
            var namePhoto = "photo.jpg";
            var visualFile = new Parse.File(namePhoto, inputVisualFile);
            var name = document.getElementById('inputName').value;
            if (visualUpload.files.length > 0) {
                if(name=="" || name==null)  {
                    alert("記入していない項目があります。");
                }else{
                    cardSave.set("mainVisual", visualFile);
                    cardSave.set("name", name);
                    cardSave.save(null, {
                        success: function() {
                            alert('新しい名刺を作成しました!');
                        }, error: function(error) {
                            alert('エラーコード: ' + error.description);
                        }
                    });
                }
            }else{
                alert("Ooops! No visual file!");
            }
        }

and this is an HTML input

<input type="file" id="inputVisual">

I could save files on this code a couple of days before. So I get back to some old versions of my code for removing this bug, but that doesn't work.

Also I researched the following related Question but it didn't work.

How to save an Image in Parse.com via JavaScript?

And my site is using CloudFlare, though I don't know it is an relevant factor.

I really appreciate if anyone give me a solution. Thank you for your reading.

Community
  • 1
  • 1
  • its means that you are using wrong key. have you created different project for development and production.? – Kishore Jethava Dec 18 '15 at 05:49
  • @kishorejethava Thank you for your comment. I checked the Parse Initializing key again, but the problem continues.... The bug might be because of other points. First, I haven't created any new project. Second other DB functions using Parse Javascript SDK are still working in the same HTML file using the same Parse initializing key. – Shohei Kodama Dec 18 '15 at 14:16

1 Answers1

0

I came across the exact same issue in that it started creating this error only after yesterday, and never before. And never had I made changes to my Parse Keys or File save functions. Today I solved it to work for me after re-reading the parse documentation:

Wrap this:

cardSave.set("mainVisual", visualFile);
cardSave.set("name", name);
cardSave.save(null, {
    success: function() {
        alert('新しい名刺を作成しました!');
    }, error: function(error) {
        alert('エラーコード: ' + error.description);
    }
});

inside of this:

parseFile.save().then(function() {
    //Your cardSave set and save
}, function(error) {

});

Hope that works!

  • Thank you for your comment! Surprisingly, my code started to work today though I didn't change anything. Actually I tried your approach but I can't solve the problem at that time. So I can't know the reason.... Anyway thank you for your comment! – Shohei Kodama Dec 19 '15 at 06:11