get image and upload/save it in server location

vkc picture vkc · Jun 12, 2015 · Viewed 22.4k times · Source

I have an beego application in which i have a requirement of uploading a image from client for to server location.

using this script, when i click on empty image(click here to add) it is displaying a browse file option.After selecting the image no action taking place. My requirement is on selection of image from browse option, the selected image should be saved in server location.

Answer

Mahesh Jasti picture Mahesh Jasti · Jun 12, 2015

localStorage that you are using is something like cookies and would never be saved in server. It is per domain saved on the client side.

Also when you want to save the bit to server, you need to do a form post and you should be having some sort of server side code with handles the saving part like where to save and in which format.

Try exploring Php or ASP.NET or Jsp file upload - saving on server. With out server side code it would not be possible to push data using HTML and Javascript alone, as they are only client side scripts.

Update 1: html

<form action="/post/save" method="POST" enctype="multipart/form-data">
    <input type="file" name="images">
</form>

Controller

file, header, err := this.GetFile("images")
if err != nil {
    log.Println("error", err)
} else {
    log.Println("filename", header.Filename)
}

Try some docs on Beego GetFile method. But there seems to be a limitation there like by default, you cannot handle multiple uploaded files at a time.