3
votes

with this code the upload is done correctly

<script>
var data = { "timestamp": "1403951115",
"callback": "http://localhost:8080/SimpleServlet/cloudinary_cors.html",
"signature": "3b1a708393db7cd0ef1df2be0c602ea99d9c64c3",
"api_key": "742866863611915" };
$('#uploadinput').attr('data-form-data', JSON.stringify(data));
</script>

if i set dinamically value for 'data-form-data' attribute the upload fail with error: "Upload preset Must specify upload preset when using unsigned upload"

Note that i set dinamically data value using an ajax asynchronous call to cloudinary server to take the credentials.

2
please supply some code alsoPratik

2 Answers

1
votes

To avoid this issue and to start from, I have used the following approach:

<script src="//widget.cloudinary.com/global/all.js" type="text/javascript"></script>
<script>
    cloudinary.setCloudName('YOUR_CLOUD_NAME');
    cloudinary.openUploadWidget({upload_preset: 'your_unsigned_preset_name'}, function(error, result) {//...
    })
</script>
0
votes

Modifying the parameters of the cloudinary-fileupload field by calling $(...).attr('data-form-data', json) does not work since the value of this attribute is not re-read after initialization, so this call has no effect. Possible consequences are 401 Unauthorized (e.g. because of Unknown API Key) error and the original parameters being used.

The correct way to update the upload parameters is to call $(...).fileupload({formData: data}) where data is the parameters hash (not JSON serialized).