Gotcha - passing them as URL parameters worked perfectly - thanks!
I know this is kind of old, but could somebody please explain how the putFile method works? I don’t understand how you pass in the file you want to upload to your dropbox.
Thanks!
EDIT: Actually I figured it out. For anyone else who might not understand at first this is what you need
------------------------------------------------- -- --In download.lua -- ------------------------------------------------- local function networkListener( event ) if ( event.isError ) then print( "Network error!" ) else print ( event.response) end end local function handleSendEvent( event ) if ( "ended" == event.phase ) then print( "Send button was pressed and released" ) local path = "\<pathtoyourfile\>.json" --In my case I needed to sync json local headers = {} headers["Content-Type"] = "application/json" local params = {} params.headers = headers -- Tell network.request() to get the request body from a file: params.body = { filename = path, baseDirectory = system.DocumentsDirectory } dropbox.putFile( path, networkListener, params ) end end local sendButton = widget.newButton { left = 100, top = 400, id = "request", label = "Send File", onEvent = handleSendEvent } ------------------------------------------------- -- --In dropboxModule.lua -- ------------------------------------------------- function M.putFile( path, listener, params ) local url = "https://api-content.dropbox.com/1/files\_put/dropbox/" .. path .. "?" .. authString network.request( url, "PUT", listener, params ) end
I know this is kind of old, but could somebody please explain how the putFile method works? I don’t understand how you pass in the file you want to upload to your dropbox.
Thanks!
EDIT: Actually I figured it out. For anyone else who might not understand at first this is what you need
------------------------------------------------- -- --In download.lua -- ------------------------------------------------- local function networkListener( event ) if ( event.isError ) then print( "Network error!" ) else print ( event.response) end end local function handleSendEvent( event ) if ( "ended" == event.phase ) then print( "Send button was pressed and released" ) local path = "\<pathtoyourfile\>.json" --In my case I needed to sync json local headers = {} headers["Content-Type"] = "application/json" local params = {} params.headers = headers -- Tell network.request() to get the request body from a file: params.body = { filename = path, baseDirectory = system.DocumentsDirectory } dropbox.putFile( path, networkListener, params ) end end local sendButton = widget.newButton { left = 100, top = 400, id = "request", label = "Send File", onEvent = handleSendEvent } ------------------------------------------------- -- --In dropboxModule.lua -- ------------------------------------------------- function M.putFile( path, listener, params ) local url = "https://api-content.dropbox.com/1/files\_put/dropbox/" .. path .. "?" .. authString network.request( url, "PUT", listener, params ) end
I used your code to create a module that sends a text file to dropbox or downloads one into the app. This works just fine on the Corona emulator and on iOS but it is not working right on Android.
I started a thread here:
http://forums.coronalabs.com/topic/55694-networkrequest-not-getting-a-response-from-android/
However, it seems you all might be more likely to know what my issue is.
On Android, I can download files but when I try to upload a file the server never responds. My callback doesn’t ever fire. I have been messing around with my build.settings file and haven’t got it working. I added these permissions: “android.permission.WRITE_EXTERNAL_STORAGE”,
“android.permission.ACCESS_NETWORK_STATE”,
I have also attempted to write an intent filter:
{
actions = {“android.intent.action.SEND”, “android.intent.action.SEND_MULTIPLE”},
categories = {“android.intent.category.DEFAULT”},
data = {mimeType=“text/plain”}
}
Honestly, I am just kind of guessing on these attempts to fix the problem.
The error I’m getting from the device is:
Calling a method in the system process without a qualified user: android.app.ContextImpl.sendBroadcast:1468 com.android.server.InputMethodManagerService$4.run:2747 java.lang.Thread.run:841 <bottom of call stack> <bottom of call stack>
Before changing the build.settings I was getting a different error:
Permission Denial: opening provider com.google.android.gsf.gservices.GservicesProvider from ProcessRecord{4471b0e8 25480:com.mycomp.myapp/000000} (pid=00000, uid=00000) requires com.google.android.providers.gsf.permission.READ_GSERVICES or com.google.android.providers.gsf.permission.WRITE_GSERVICES
Any advice is appreciated.
I used your code to create a module that sends a text file to dropbox or downloads one into the app. This works just fine on the Corona emulator and on iOS but it is not working right on Android.
I started a thread here:
http://forums.coronalabs.com/topic/55694-networkrequest-not-getting-a-response-from-android/
However, it seems you all might be more likely to know what my issue is.
On Android, I can download files but when I try to upload a file the server never responds. My callback doesn’t ever fire. I have been messing around with my build.settings file and haven’t got it working. I added these permissions: “android.permission.WRITE_EXTERNAL_STORAGE”,
“android.permission.ACCESS_NETWORK_STATE”,
I have also attempted to write an intent filter:
{
actions = {“android.intent.action.SEND”, “android.intent.action.SEND_MULTIPLE”},
categories = {“android.intent.category.DEFAULT”},
data = {mimeType=“text/plain”}
}
Honestly, I am just kind of guessing on these attempts to fix the problem.
The error I’m getting from the device is:
Calling a method in the system process without a qualified user: android.app.ContextImpl.sendBroadcast:1468 com.android.server.InputMethodManagerService$4.run:2747 java.lang.Thread.run:841 <bottom of call stack> <bottom of call stack>
Before changing the build.settings I was getting a different error:
Permission Denial: opening provider com.google.android.gsf.gservices.GservicesProvider from ProcessRecord{4471b0e8 25480:com.mycomp.myapp/000000} (pid=00000, uid=00000) requires com.google.android.providers.gsf.permission.READ_GSERVICES or com.google.android.providers.gsf.permission.WRITE_GSERVICES
Any advice is appreciated.
I couldnt get access to this code , could anyone please send me a link, this code description sounds really interesting to work with
I couldnt get access to this code , could anyone please send me a link, this code description sounds really interesting to work with