Discussion:
Test::Mojo with uploading files
(too old to reply)
y***@g.ucla.edu
2018-01-03 03:09:49 UTC
Permalink
Hello all,

How do I ask the test object to upload files?
Here's the source code for dragging files to the drop zone:

<form action="/uploadsave" method="post" class="dropzone" id="dropzoneform" enctype="multipart/form-data"> </form>
<script type="text/javascript"> Dropzone.options.dropzoneform = { init: function() { uploadMultiple: true, this.on("queuecomplete", function() { console.log("queue completed."); window.location.reload(true); }); this.on("success", function(file, response) { console.log(file.name + " files successfully uploaded."); }); this.on("error", function(file, errorMessage) { console.log(errorMessage); }); } }; </script>

And the source code for selecting a file to submit:

<form action="/uploadsave" id="uploadform" method="post" enctype="multipart/form-data" style="display:block"> <label for="idupload">Upload A New File: </label> <input type="file" name="file" id="idupload" style="display:inline" > </form> <script> document.getElementById("idupload").onchange = function() { document.getElementById("uploadform").submit(); } </script>

Thanks!

Ni
--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
Daniel Mantovani
2018-01-04 21:53:28 UTC
Permalink
Hi,

You can find an example of file upload testing here:
https://metacpan.org/pod/Test::Mojo#post_ok

I haven't tested what follows, but in your case (using "file" as the name
of the file input field and "/uploadsave" as the url to post) that should
be:

my $upload = {file => {file => '/path/to/the/file/to/upload'}};
$t->post_ok('/uploadsave' => form => $upload)->status_is(200);

(the first "file" corresponds to the name of the input field, and that will
be the name of the parameter at your controller. The second "file" tells
the user agent that it should upload the file that follows);

Hope it helps.
BR,
Post by y***@g.ucla.edu
Hello all,
How do I ask the test object to upload files?
<form action="/uploadsave" method="post" class="dropzone" id="dropzoneform" enctype="multipart/form-data"> </form>
<script type="text/javascript"> Dropzone.options.dropzoneform = { init: function() { uploadMultiple: true, this.on("queuecomplete", function() { console.log("queue completed."); window.location.reload(true); }); this.on("success", function(file, response) { console.log(file.name + " files successfully uploaded."); }); this.on("error", function(file, errorMessage) { console.log(errorMessage); }); } }; </script>
<form action="/uploadsave" id="uploadform" method="post" enctype="multipart/form-data" style="display:block"> <label for="idupload">Upload A New File: </label> <input type="file" name="file" id="idupload" style="display:inline" > </form> <script> document.getElementById("idupload").onchange = function() { document.getElementById("uploadform").submit(); } </script>
Thanks!
Ni
--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
Continue reading on narkive:
Loading...