Archived from the Transloadit support forum. Originally posted on January 3, 2013; details may be outdated, see our docs for current behavior. Original thread
Hi guys! Thx for such a great service.
I have a question…
Is it possible to use “http/import” robot for importing dynamic array of urls (not one url, but an array).
E.g. I’m trying to store many images (which are available via urls) from instagram to my s3 bucket.
The template I was trying to use looks like this:
{
"steps": {
"import": {
"robot": "/http/import",
"url": "${fields.photo_url}"
},
"thumb": {
"use": ["import"],
"robot": "/image/resize",
"width": 70,
"height": 70,
"resize_strategy": "crop"
},
"export": {
"use": ["thumb", "import"],
"robot": "/s3/store",
"key": "REDACTED",
"secret": "REDACTED",
"bucket": "*************"
}
}
}
I know that I can hardcode urls in template as an array, but is it possible to send an array of urls via http, that is the question?
Thank you guys! Merry Christmass!
tim-kos
(Tim Koschützki)
January 4, 2013, 7:06am
2
Hey Aleksey,
thanks for the question - this is actually a very good one. It is currently not possible, but I understand that this would be a good feature.
How are you sending this array via http? Do you have an example page where I can take a look?
kind regards,
Tim
Co-Founder Transloadit
@tim_kos
Hi Tim,
Thanks for the reply.
This is a snippet of code written in Grails Server Page (*.gsp) markup.
<g:uploadForm id="facebook-upload-form" class="form-modal" url="http://api2.transloadit.com/assemblies">
<div class="modal-body">
<div id="upload-facebook">
<div class="photos-container"></div>
<input type="hidden" name="params"
value='{"auth":{"key":"${grailsApplication.config.transloadit.api.key}"},"template_id":"${grailsApplication.config.transloadit.templates.avatarImport}","redirect_url":"${grailsApplication.config.grails.serverURL}/profile/savePhotos"}'>
<input type="hidden" name="photo_url" value="">
</div>
<div id="facebook-progress" class="progress progress-info progress-striped active hide">
<div id="facebook-progress-bar" class="bar" style="width: 0"></div>
</div>
</div>
<div class="modal-footer">
<button class="btn btn-danger" data-dismiss="modal" aria-hidden="true">Cancel</button>
<button type="submit" class="btn btn-success" name="upload">Upload</button>
</div>
</g:uploadForm>
And a call to js transloadit plugin:
$('#facebook-upload-form').transloadit({
onStart: function () {
$('#upload-facebook').hide();
$('#facebook-progress').show();
},
onProgress: function (bytesReceived, bytesExpected) {
var progress = Math.round(bytesReceived / bytesExpected * 100);
$('#facebook-progress-bar').css('width', progress + '%').html(!isNaN(progress) ? progress + '%' : '');
},
onUpload: function () {
$('#facebook-progress-bar').html('Processing...');
},
modal: false,
wait: true,
fields: true
});
This stuff works for a single url import. I tried to send multiple comma-separated urls in different ways, but all they didn’t work. Template allow to set multiple import files only in a “hard-code” way.
This would be very cool if user would be able to send an array of urls, e.g.:
<input name="urls" value="['http://url/to/image.jpg','http://url/to/another/image.png']">
Perhaps not the best solution…
Best regards,
Aleksey
tim-kos
(Tim Koschützki)
January 4, 2013, 3:40pm
4
Hey Aleksey,
I understand. The easiest would be to make them comma-separated, like so:
<input name=“urls” value="http://url/to/image.jpg ,
http://url/to/another/image.png <http://url/to/another/image.png’>"> ;
However, the comma itself is actually a valid character to be used in urls (although it’s not common), so we’d need a different syntax.
Also this should probably work as well:
<input name=“urls[]” value="http://url/to/image.jpg"> ;
<input name=“urls[]”
value="http://url/to/another/image.jpg<http://url/to/image.jpg> ;
">
What do you think?
tim-kos
(Tim Koschützki)
January 8, 2013, 1:14pm
5
Hey Aleksey,
I just pushed a patch that allows url strings separated by “|”. It should be deployed within the next 30 minutes.
Please let me know how it goes.
kind regards,
Tim
Co-Founder Transloadit
@tim_kos
Hey Tim,
I tried to import multiple photos urls using jquery plugin with redirect_url, but no luck. Here’s the input which I used:
<input type="hidden" name="photo_url" value='http://url/to/image.jpg|http://url/to/another/image.png'>
$('#my-upload-form').transloadit({wait:true, fields:true});
Assemly was successful, but only one file was processed, please take a look at screenshot I attached to this post.
The template I used is like in my first post of this discussion. I had passed a string of “|”-separated urls for input[name=photo_url], no luck though.
The interesting thing that only second file was processed, not the first, which perhaps is more obvious.
Am I doing something wrong?
Thx to you and your team for taking care about your users!
Kind regards,
Aleksey
tim-kos
(Tim Koschützki)
January 9, 2013, 11:05am
7
Hey Aleksey,
I can’t see a screenshot attached to the ticket. : /
Also, could you please tell me the assembly id so that I can check out the assembly?
kind regards,
Tim
Co-Founder Transloadit
@tim_kos
Hey Tim,
Oh, sorry somehow it got lost.
Assembly id is: REDACTED
Screenshot is below.
Best regars,
Aleksey
tim-kos
(Tim Koschützki)
January 10, 2013, 8:22am
9
Okay that’s weird. I just created a new template with this JSON:
`{ “steps”: {
"encode": {
"robot": "/http/import",
"url": "http://sphotos-b.ak.fbcdn.net/hphotos-ak-prn1/s720x720/151005_479699705430464_2087141384_n.jpg|http://sphotos-d.ak.fbcdn.net/hphotos-ak-prn1/39585_107964202604018_4661889_n.jpg",
"result": true
}
} }`
and it worked fine (cool photos by the way).
Could you add a “result”: true to your import step and see which files it imports?
kind regards,
Tim
Co-Founder Transloadit
@tim_kos
Hey, Tim
I’ve tried to edit template according to your recommendations, and here’s the result:
Assembly id: REDACTED
It has imported one and the same file twice. However photo_url parameter has two different urls separated by “|”.
Best regards,
Aleksey
tim-kos
(Tim Koschützki)
January 10, 2013, 1:42pm
11
Hey Aleksey,
now I know what the problem is. A fix is underway.
I will let you know once it’s live.
kind regards,
Tim
Co-Founder Transloadit
@tim_kos
tim-kos
(Tim Koschützki)
January 10, 2013, 4:49pm
12
Hey Aleksey,
it should work now, please try again.
kind regards,
Tim
Co-Founder Transloadit
@tim_kos
Hey Tim,
Yes, now it worked just great! Very cool!
Thank you very much, Tim!
Best regards,
Aleksey
tim-kos
(Tim Koschützki)
January 11, 2013, 11:34am
14
Alright, closing this.
kind regards,
Tim
Co-Founder Transloadit
@tim_kos