Android Question Upload file to web, without user intervention

Discussion in 'Android Questions' started by vecino, Jan 11, 2019.

  1. vecino

    vecino Well-Known Member Licensed User

    Hi, I've searched the forums, but I have not found what I want.
    I need to upload files to a website, but without user intervention.
    I do not know if it is possible.
    Thank you.
     
  2. Sandman

    Sandman Well-Known Member Licensed User

    It's possible.
     
  3. vecino

    vecino Well-Known Member Licensed User

    I believe you :)
    Thanks, can you tell me how?
    Any link?
     
  4. Sandman

    Sandman Well-Known Member Licensed User

    It's kind of a broad subject, and you're very vague, so it's difficult to give good help. But here's some bullet points for you to work with:

    Doing things without user intervention
    Look into using a service, the forum is full of info about this.

    Upload files to a website
    Your best options are probably to either use an api on the server that accepts your uploads, or set up a public ftp server. I'm fairly certain that the forum contains info on uploading files using ftp, and it's fairly simple doing the same using a simple api on the server. Either way you need to have a lot of cooperation of the server.

    I can't really give better help than this without a detailed description on what it is that you're trying to accomplish.
     
  5. DonManfred

    DonManfred Expert Licensed User

    The correct answer is given.
    I guess this is not what you want? Think over how you ask questions.
    Do not ask yes/no questions if you do not expect to get YES or NO as answer.

    As written by @Sandman your question is really vague.

    Where do you want to upload files to?
    - To your server?
    - To your customers server?
    - To any server?
     
    Sandman likes this.
  6. vecino

    vecino Well-Known Member Licensed User

    Sorry, I just reviewed my initial question and I have omitted data.
    What I need is to upload text files using http. No ftp.
    And it's my server web.
    Thank you.
     
  7. vecino

    vecino Well-Known Member Licensed User

    I know it's not an excuse, but today I forgot my glasses at home and I'm using the smartphone almost blindly.
     
  8. DonManfred

    DonManfred Expert Licensed User

    You need to have a server component running on the server which accepts fileuploads. A B4J app, a PHP Script.

    Do a Job.Postmultipart using okhttputils2 to upload files to the endpoint accepting fileuploads.

    Basically the code must be something like

    Code:
    Dim j As HttpJob
        j.Initialize(
    "", Me)
        
    Dim m As Map = CreateMap("additionalfield":"additional data")
        
        
    Dim filelist As List  ' List holding all files to Upload
        filelist.Initialize
        
        
    Dim fd As MultipartFileData ' Create a MultipartFileData for each file to upload
        fd.Initialize
        fd.Dir = 
    File.DirAssets
        fd.FileName = 
    "testfiletoupload.txt"
        fd.ContentType = 
    "Text/Plain"
        fd.KeyName = 
    "Testfile"
        
        filelist.Add(fd) 
    ' and add the MultipartFileData to the list
        
        j.PostMultipart(
    "http://domain.com/uploadendpoint.php",m,filelist) ' Upload the files and also giving the additional Values (m Map) to the uploadendpoint
        Wait For (j) JobDone(j As HttpJob)
        
    If j.Success Then
            
    Log(j.GetString)
        
    End If
        j.Release
     
    inakigarm and hibrid0 like this.
  9. vecino

    vecino Well-Known Member Licensed User

    Hello, and sorry for the time elapsed.
    I had to buy a new glasses, I can not find the old glasses.
    I have not been able to work until now.

    CreateMap("additionalfield":"additional data")

    Is additionalfield a variable?
    Is additional data the name of the file?
    Thank you.
     
  10. DonManfred

    DonManfred Expert Licensed User

    it is the key additionalfield which is sended.
    like the get value in a url ("domain.com/index.php?additionalfield=additional data")
    no
    Code:
    Dim fd As MultipartFileData ' Create a MultipartFileData for each file to upload
        fd.Initialize
        fd.Dir = 
    File.DirAssets ' Path on device
        fd.FileName = "testfiletoupload.txt" ' filename on device to upload
        fd.ContentType = "Text/Plain"
        fd.KeyName = 
    "Testfile" ' the key used to identify
     
    hibrid0 likes this.
  11. vecino

    vecino Well-Known Member Licensed User

    Perfect.
    Many thanks.
    It worked perfectly.
    :):):)
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice