Android Question curl request to b4a

mhartwig

Member
Licensed User
Longtime User
Can someone help me with this curl request?

Code:
curl -X POST -H "QB-Token: e7cde5f7f5b93f3fa5ac72a281777cbf0f908374" -d "field_name=avatar" -F "[email protected]" https://api.quickblox.com/data/<Class_name>/<record_id>/file.json

Where does the -f file= part come in? It isnt just a regular poststring I guess. I am using httputils2.
 
Hey mhartwig, I had the same problem, look my solution:

where I test with this line:
curl --header "Content-Type: audio/amr; rate:8000" --data-binary @MiGravacion.amr "http://www.myserver.com"

now is working with this:

Dim strFolder As String = "/sdcard/Download/"
Dim strFile As String = "MiGravacion.amr"
Dim In As InputStream = File.OpenInput(strFolder,strFile)
Dim size As Long = File.size(strFolder,strFile)
Dim request As HttpRequest
request.InitializePost(
http://www.myserver.com/, In, size)
request.SetHeader("Content-Type", "audio/amr; rate=8000;")
request.SetContentType ("audio/amr; rate=8000;")
request.Timeout = 60000
objHCGoogle.Execute(request, 1000)
 
Upvote 0

I am receiving "Wrong Arguments" from the api.

I used the class here:
http://www.b4x.com/android/forum/threads/multipart-formdata.30873/#post-179487

I added this to httpjob
Code:
Public Sub UploadFile(NV As Map, Files As List, Link As String)
    req = MultipartPost.CreatePostRequest(Link, NV, Files)
    CallSubDelayed2(HttpUtils2Service, "SubmitJob", Me)
End Sub

I then do this
Code:
Public Sub UploadFileForRecord(ClassName As String, RecordID As String, Dir As String, FileName As String, FieldName As String, Token As String)
    Dim job As HttpJob
    job.Initialize("UploadFileForRecord", Me)
   
    Dim nv As Map
    nv.Initialize
    nv.Put("Field_Name", FieldName)
   
    Dim files As List
    files.Initialize
   
    Dim fd As FileData 
    fd.Initialize
    fd.Dir = Dir
    fd.FileName = FileName
    fd.KeyName = "File"
    fd.ContentType = "application/octet-stream"
   
    files.Add(fd)
   
    Dim url As String
    url = "https://api.quickblox.com/data/<Class_name>/<record_id>/file.json".Replace("<Class_name>", ClassName) _
        .Replace("<record_id>", RecordID)
   
    job.UploadFile(nv, files, url)
    job.GetRequest.SetHeader("QB-Token", Token)
End Sub
 
Upvote 0
Hey mhartwig, I had the same problem, look my solution:

where I test with this line:
curl --header "Content-Type: audio/amr; rate:8000" --data-binary @MiGravacion.amr "http://www.myserver.com"

now is working with this:

Dim strFolder As String = "/sdcard/Download/"
Dim strFile As String = "MiGravacion.amr"
Dim In As InputStream = File.OpenInput(strFolder,strFile)
Dim size As Long = File.size(strFolder,strFile)
Dim request As HttpRequest
request.InitializePost(
http://www.myserver.com/, In, size)
request.SetHeader("Content-Type", "audio/amr; rate=8000;")
request.SetContentType ("audio/amr; rate=8000;")
request.Timeout = 60000
objHCGoogle.Execute(request, 1000)

Thanks, I will try this.
 
Upvote 0
Well i am officially stuck with this and my app development is pretty much dead without this working. I get an internal server error with the other code. The curl request works fine, so it is obviously my app.
 
Upvote 0
I fixed the case:

Code:
Public Sub UploadFileForRecord(ClassName As String, RecordID As String, Dir As String, FileName As String, FieldName As String, Token As String)
    Dim job As HttpJob
    job.Initialize("UploadFileForRecord", Me)
   
    Dim nv As Map
    nv.Initialize
    nv.Put("field_name", FieldName)
   
    Dim files As List
    files.Initialize
   
    Dim fd As FileData 
    fd.Initialize
    fd.Dir = Dir
    fd.FileName = FileName
    fd.KeyName = "file"
    fd.ContentType = "application/octet-stream"
   
    files.Add(fd)
   
    Dim url As String
    url = "https://api.quickblox.com/data/<Class_name>/<record_id>/file.json".Replace("<Class_name>", ClassName) _
        .Replace("<record_id>", RecordID)
   
    job.UploadFile(nv, files, url)
    job.GetRequest.SetHeader("QB-Token", Token)
End Sub

I still get this error though:
Code:
{"errors":["Wrong arguments"]}
 
Upvote 0
Not sure if this part will help:

Code:
Content-Disposition: form-data; name="file"; filename="download.jpg";Content-Type: application/octet-stream
 
Upvote 0
Back
Top