After successfully figuring out (with assistance here) how to download an .mp3 file from the internet, I am trying upload a .txt file to the internet.
The libraries I have installed are: Core (v 8.30), OkHttp (v 1.2), RuntimePermissions (v 1.1), and StringUtils (v 1.12)
I also have HttpJob and HttpUtils2Service installed as Modules.
I tried modifying several examples from the Forum. I don't really understand MultipartFileData and the corresponding PostMultipart. I just guessed on the fd.KeyName and fd.ContentType and the first two arguments of PostMultipart. "https://gap.thorconsulting.net/joshmusic/" is the path to where I want to upload NoteTest.txt".
When I run UploadFile, I get the following error:
ResponseError. Reason: Not Found, Response: <!DOCTYPE html>
Which is followed my what looks to be an HTML document
I'm not sure what to try next.
Here is the subroutine:
The libraries I have installed are: Core (v 8.30), OkHttp (v 1.2), RuntimePermissions (v 1.1), and StringUtils (v 1.12)
I also have HttpJob and HttpUtils2Service installed as Modules.
I tried modifying several examples from the Forum. I don't really understand MultipartFileData and the corresponding PostMultipart. I just guessed on the fd.KeyName and fd.ContentType and the first two arguments of PostMultipart. "https://gap.thorconsulting.net/joshmusic/" is the path to where I want to upload NoteTest.txt".
When I run UploadFile, I get the following error:
ResponseError. Reason: Not Found, Response: <!DOCTYPE html>
Which is followed my what looks to be an HTML document
I'm not sure what to try next.
Here is the subroutine:
B4X:
Sub UploadFile
Log("Start upload")
Dim upload As HttpJob
upload.Initialize("Upload",Me)
Dim fd As MultipartFileData
fd.Initialize
fd.KeyName = "Text"
fd.Dir = SDpathname
fd.FileName = "NoteTest.txt"
fd.ContentType = "text"
upload.Username = "____"
upload.Password = "________"
upload.PostMultipart("https://gap.thorconsulting.net/joshmusic/UploadText.php", CreateMap("param1": "value1"), Array(fd))
Wait For (upload) JobDone(upload As HttpJob)
If upload.Success Then
Log("File Uploaded")
Else
Log("***Error: " & upload.ErrorMessage)
ToastMessageShow("Error: " & upload.ErrorMessage, True)
End If
upload.Release
End Sub