PDA

View Full Version : How to upload image file on existing server by my own javascript-prototype code



alexblade
09-11-2015, 09:28 AM
is possible to upload my local image file with my local javascript/prototype code on existing site ?

existing site has its own upload file dialog window, but I want upload the file bypassing existing dialog window

styxlawyer
09-11-2015, 02:59 PM
Yes, it's possible but probably not a good idea to allow anyone to upload random stuff to your website. If it's not your website but belongs to someone else, one might ask why you want to do this.

Try Google for "JavaScript file upload".

alexblade
09-14-2015, 10:04 AM
pls look:

existing form


<form id="js-add-form" action="" class="board__content container_25 cf" method="post" data-confirm-text="Вы уверены, что хотите уйти с этой страницы? Несохраненные данные будут потеряны!">

<a href="" id="fileupload-button">Добавить фотографию</a>

<input id="fileupload-file-input" name="file" accept="image/gif, image/jpeg, image/png" style="position: absolute; top: -10000px" multiple="" type="file">

<section class="board__content__photo__body grid_20" style="display: none;" id="filupload-media-container">

</section>

<button class="board__content__further__body"><span>далее</span></button>
from this site (need login) https://999.md/add?category=furniture-and-interior&subcategory=furniture-and-interior%2Fupholstery&offer_type=776

this form uses main.js - https://www.evernote.com/shard/s212/sh/933899a9-0823-4322-bd60-240e92fb05ba/ab7e0e6bdc57e7cb9165f34cab8ee10b

I want to fill this form with selenium... as automation test... w/o File Upload Dialog window
I can with selenium to fill all fields except [image upload]
I can put image file to input field with selenium

browser.file_field(:id, "fileupload-file-input").set '//1.jpg'
but I can't understand what (and how) method/function I should initialize from main.js that my file from input field will be uploaded to server
I practical don't know prototype. and little bit know javascript

alexblade
09-14-2015, 10:08 AM
this tag
<a href="" id="fileupload-button">Добавить фотографию</a>
uses the follow event

return function(e) {
return e.preventDefault(), t.openFileUploadDialog()
}

and this tag
<input id="fileupload-file-input" name="file" accept="image/gif, image/jpeg, image/png" style="position: absolute; top: -10000px" multiple="" type="file">
uses

return function(o) {
var n;
return n = o.currentTarget.files, t.each(n, function(t, o) {
return e.options.remaining > 0 ? e._upload(n.item(o)) : void 0
}), e.options.nodes.fileInput.val("")
}

I need upload file w/o dialog window
with selenium I put file to input field

browser.file_field(:id, "fileupload-file-input").set '//1.jpg'

but what next I dont know :(
how to upload my file from input field to server ? :(