Issue #372Opened October 4, 2017by deffrin0 reactions

Asset Manager not automatically add images to assets after uploading

Question

The JSON response of an upload is like this {"data":["http://url.com/flower.jpg"]}

The response event is working.In the response event response is in the format of string. Content-type is set to application/json when uploaded file.

Now I manually add image to assets in the response event. Is there any problem in the response format I get after a file upload?

Answers (3)

sonnylloydOctober 4, 20170 reactions

I have the same problem and like you i added the files manually. just in case someone else looks at this and needs to achieve the same thing manually

editor.on('asset:upload:response', (response) => {
                var result = JSON.parse(response);
                editor.AssetManager.add(result.data);
            });
var result = JSON.parse(response);
                editor.AssetManager.add(result.data);
            });

my response looks like this

{"data":[{"type":"image","height":100,"width":100,"src":"https://www.sunzu.com/updated/cdn/696567-ea0401d4141da8ee123e8c76aa1483b955b74110.jpg"}]}

@artf i believe the issue here is inside src\asset_manager\view\FileUploader.js you have on line 77 inside onUploadResponse(text)

const json = typeof text === 'text' ? JSON.parse(text) : text;

this should be

const json = typeof text === 'string' ? JSON.parse(text) : text;
artfOctober 4, 20170 reactions
typeof text === 'text' 

LOL Yeah I'd say it's definitely the reason behind the bug Would you like to PR it? :)

sonnylloydOctober 4, 20170 reactions

@artf thanks i have sent a PR

Related Questions and Answers

Continue research with similar issue discussions.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.