3 Replies Latest reply on Apr 30, 2013 10:17 AM by DecisionPoint Keith Gable

    Uploading a file to remote server

      I have tried 3 methods without any luck.

       

      1. FTP class from Ruby net-ftp, it always thrown an exception telling it can not load the monitor.rb class

       

      2. FileTransfer explained here http://docs.rhomobile.com/rhoelements/FileTransfer, it always says "constant missing FileTransfer"

       

      3. AsyncHTTP appears to be the most successful one since a lot of people talks about it but i really don't know how to implement the server that will receive the file, i have tried with php file.

       

       

      Can anyone give me a working example.

       

      Regards,

        • Re: Uploading a file to remote server
          Kutir Mobility

          Hi Edgar,

           

          We use Rails as our backend server, in server side we receive uploaded file like

            Parameters: {"pdf_document"=>#<ActionDispatch::Http::UploadedFile:0x38b5180 @original_filename="sample_1.pdf", @conten

          t_type="application/octet-stream", @headers="Content-Disposition: form-data; name=\"pdf_document\"; filename=\"sample_1.

          pdf\"\r\nContent-Type: application/octet-stream\r\nContent-Length: 54836\r\n", @tempfile=#<File:C:/Users/AppDat

          a/Local/Temp/RackMultipart20130426-6768-1754ow1>>, "flag"=>"rhodes", "file_name"=>"test_from_rhodes"}

          Here "pdf_document" is a pdf file uploaded from rhodes.

           

          Thanks

          Surendran S

          Kutir Mobility

            • Re: Uploading a file to remote server

              Excellent.

               

              I created a method in a controller to see all parameters so i can start to play with this. I leave here for future users

               

              def receiver

                  name =  "test.txt" #upload['datafile'].original_filename

                  directory = "public/"

                  # create the file path

                  path = File.join(directory, name)

                  # write the file

                 File.open(path, "wb") { |f| f.write(params) }

              end

            • Re: Uploading a file to remote server
              DecisionPoint Keith Gable

              AyncHttp or Net::HTTP will work to send it. The server gets it as a multipart/form-data MIME-type, which is then exposed into your development platform in a number of different ways. In PHP, you should get access to the file in the $_FILES array. In Rails, the file is available in params. If you use Net::HTTP, I would suggest using this multipart POST library to make it simpler to multipart POST.

               

              Edit: You will need to load the net-http extension before you can use the library I linked above.