user1986494
user1986494

Reputation: 53

Cloudinary direct browser upload failed when i dynamically set attribute 'data-form-data' of upload input

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.

Upvotes: 3

Views: 1158

Answers (2)

Oleksii Kyslytsyn
Oleksii Kyslytsyn

Reputation: 2426

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>

Upvotes: 1

Itay Taragano
Itay Taragano

Reputation: 1931

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).

Upvotes: 0

Related Questions