FAQ
I have something like this in jquery

$.ajax({
url: 'server/uploadhandler',
data: new FormData(file[0]),
cache: false,
contentType: false,
processData: false,
type: 'POST',
success: function(data){
alert(data);
}});

Now how do i read this file in golang upload handler?

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Kyle Lemons at Apr 16, 2013 at 5:51 am
    http.FormFile <http://tip.golang.org/pkg/net/http/#Request.FormFile>? I'm
    not familiar with FormData, but that's how you do it with a normal POST
    that has file data.

    On Mon, Apr 15, 2013 at 10:38 PM, kar wrote:

    I have something like this in jquery

    $.ajax({
    url: 'server/uploadhandler',
    data: new FormData(file[0]),
    cache: false,
    contentType: false,
    processData: false,
    type: 'POST',
    success: function(data){
    alert(data);
    }});

    Now how do i read this file in golang upload handler?

    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Kar at Apr 16, 2013 at 6:07 am
    f, _, err := r.FormFile("image1"); if err != nil { net.Error(w,
    err.Error()); return }

    gave me "http no such file".
    On Tuesday, April 16, 2013 1:45:31 PM UTC+8, Kyle Lemons wrote:

    http.FormFile <http://tip.golang.org/pkg/net/http/#Request.FormFile>?
    I'm not familiar with FormData, but that's how you do it with a normal
    POST that has file data.


    On Mon, Apr 15, 2013 at 10:38 PM, kar <akma...@gmail.com <javascript:>>wrote:
    I have something like this in jquery

    $.ajax({
    url: 'server/uploadhandler',
    data: new FormData(file[0]),
    cache: false,
    contentType: false,
    processData: false,
    type: 'POST',
    success: function(data){
    alert(data);
    }});

    Now how do i read this file in golang upload handler?

    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts...@googlegroups.com <javascript:>.
    For more options, visit https://groups.google.com/groups/opt_out.

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Sanjay at Apr 16, 2013 at 7:00 am
    At a guess, I'd say that the file might be under a different key than
    "image1". You can use this little function to see what file names are being
    passed to you: http://play.golang.org/p/fLK98v_P1k

    What follows are my random piece of advice for file uploads, feel free to
    ignore everything after this point.

    Instead of using FormFile, I suggest expanding the snippet I posted above
    to do what you want. req.FormFile (and the backing req.ParseMultipartForm)
    have a concept of "maxMemory", where upto maxMemory bytes are stored in
    memory, and the rest go onto temporary files on disk. If you are writing a
    typical web upload scenario, then this doesn't really do what you want.
    With a web upload scenario, you have a max upload size (to prevent DOS
    attacks), but you just want to disallow files larger than that size. With
    the behaviour that ParseMultipartForm has, the user can still upload large
    files, they just get buffered onto disk. Now, I hear you saying that you
    could merely put a limit on the total size of the POST, but that is
    unnecessarily limiting. Consider the social network case, where you want to
    allow users to upload an album, with each picture being a maximum of 2MB,
    and an album having upto 1024 photos. You'd have to set your max memory
    limit to 2GB, which lets malicious users create large quantities of
    temporary files on disk. I claim that the streaming snippet is much more
    robust, and is not even that much more code.

    Using the streaming snippet lets you support the scenario above without
    buffering all the files in-memory, or writing other files to temporary
    storage, so that your memory (and disk) usage is not a function of
    user-controlled things (i.e. the size of the files they upload). If you use
    a combination of an io.MultiWriter, a simple CountingWriter implementation,
    and an io.LimitedReader, you can SHA-512 the file(s) as you stream them to
    disk, limit the size per file, give an error when a single file goes over
    (but still continue processing the rest of the files), and support
    arbitrary number of files per upload.

    Anyways, I've rambled on long enough, carry on.

    Cheers,
    Sanjay

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • J Rebhan at Apr 16, 2013 at 7:29 am
    Why "contentType: false" ?

    I use normally "multipart/form-data" via the jQuery Form Plugin
    (http://malsup.com/jquery/form/)

    And in Firebug or Chrome Webinspector (F12 key) you can see the data that
    are being sent.

    Another 2 cents....
    Cheers/Rusco


    El martes, 16 de abril de 2013 06:38:40 UTC+1, kar escribió:
    I have something like this in jquery

    $.ajax({
    url: 'server/uploadhandler',
    data: new FormData(file[0]),
    cache: false,
    contentType: false,
    processData: false,
    type: 'POST',
    success: function(data){
    alert(data);
    }});

    Now how do i read this file in golang upload handler?
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Mattn at Apr 16, 2013 at 8:12 am
    Here is example just written that is possible to upload image file.

    https://gist.github.com/mattn/5394240

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Kar at Apr 16, 2013 at 9:32 am
    Thanks Sanjay for the advice (especially io.limitreader) and mattn for the
    working example, i've settled with iframe instead of Formdata.
    On Tuesday, April 16, 2013 1:38:40 PM UTC+8, kar wrote:

    I have something like this in jquery

    $.ajax({
    url: 'server/uploadhandler',
    data: new FormData(file[0]),
    cache: false,
    contentType: false,
    processData: false,
    type: 'POST',
    success: function(data){
    alert(data);
    }});

    Now how do i read this file in golang upload handler?
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedApr 16, '13 at 5:38a
activeApr 16, '13 at 9:32a
posts7
users5
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase