cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
What’s new: end-to-end encryption, Replay and Dash updates. Find out more about these updates, new features and more here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Re: Permission Denied - Okhttp Dispatcher

Permission Denied - Okhttp Dispatcher

kestites
Explorer | Level 4
Go to solution

I am having trouble uploading to my folder because of a permissions error

 

Here is my error: 

FATAL EXCEPTION: OkHttp Dispatcher
Process: com.example.kestites.exportdatabase, PID: 3131
java.lang.SecurityException: Permission denied (missing INTERNET permission?)
at java.net.InetAddress.lookupHostByName(InetAddress.java:464)
at java.net.InetAddress.getAllByNameImpl(InetAddress.java:252)
at java.net.InetAddress.getAllByName(InetAddress.java:215)
at okhttp3.Dns$1.lookup(Dns.java:39)
at okhttp3.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:173)
at okhttp3.internal.http.RouteSelector.nextProxy(RouteSelector.java:139)
at okhttp3.internal.http.RouteSelector.next(RouteSelector.java:81)
at okhttp3.internal.http.StreamAllocation.findConnection(StreamAllocation.java:172)
at okhttp3.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:123)
at okhttp3.internal.http.StreamAllocation.newStream(StreamAllocation.java:93)
at okhttp3.internal.http.HttpEngine.connect(HttpEngine.java:296)
at okhttp3.internal.http.HttpEngine.sendRequest(HttpEngine.java:248)
at okhttp3.RealCall.getResponse(RealCall.java:243)
at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:201)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:163)
at okhttp3.RealCall.access$100(RealCall.java:30)
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:127)
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
Caused by: android.system.GaiException: android_getaddrinfo failed: EAI_NODATA (No address associated with hostname)
at libcore.io.Posix.android_getaddrinfo(Native Method)
at libcore.io.ForwardingOs.android_getaddrinfo(ForwardingOs.java:55)
at java.net.InetAddress.lookupHostByName(InetAddress.java:451)
at java.net.InetAddress.getAllByNameImpl(InetAddress.java:252) 
at java.net.InetAddress.getAllByName(InetAddress.java:215) 
at okhttp3.Dns$1.lookup(Dns.java:39) 
at okhttp3.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:173) 
at okhttp3.internal.http.RouteSelector.nextProxy(RouteSelector.java:139) 
at okhttp3.internal.http.RouteSelector.next(RouteSelector.java:81) 
at okhttp3.internal.http.StreamAllocation.findConnection(StreamAllocation.java:172) 
at okhttp3.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:123) 
at okhttp3.internal.http.StreamAllocation.newStream(StreamAllocation.java:93) 
at okhttp3.internal.http.HttpEngine.connect(HttpEngine.java:296) 
at okhttp3.internal.http.HttpEngine.sendRequest(HttpEngine.java:248) 
at okhttp3.RealCall.getResponse(RealCall.java:243) 
at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:201) 
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:163) 
at okhttp3.RealCall.access$100(RealCall.java:30) 
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:127) 
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) 
at java.lang.Thread.run(Thread.java:818) 
Caused by: android.system.ErrnoException: android_getaddrinfo failed: EACCES (Permission denied)
at libcore.io.Posix.android_getaddrinfo(Native Method) 
at libcore.io.ForwardingOs.android_getaddrinfo(ForwardingOs.java:55) 
at java.net.InetAddress.lookupHostByName(InetAddress.java:451) 
at java.net.InetAddress.getAllByNameImpl(InetAddress.java:252) 
at java.net.InetAddress.getAllByName(InetAddress.java:215) 
at okhttp3.Dns$1.lookup(Dns.java:39) 
at okhttp3.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:173) 
at okhttp3.internal.http.RouteSelector.nextProxy(RouteSelector.java:139) 
at okhttp3.internal.http.RouteSelector.next(RouteSelector.java:81) 
at okhttp3.internal.http.StreamAllocation.findConnection(StreamAllocation.java:172) 
at okhttp3.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:123) 
at okhttp3.internal.http.StreamAllocation.newStream(StreamAllocation.java:93) 
at okhttp3.internal.http.HttpEngine.connect(HttpEngine.java:296) 
at okhttp3.internal.http.HttpEngine.sendRequest(HttpEngine.java:248) 
at okhttp3.RealCall.getResponse(RealCall.java:243) 
at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:201) 
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:163) 
at okhttp3.RealCall.access$100(RealCall.java:30) 
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:127) 
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) 
at java.lang.Thread.run(Thread.java:818) 

 

Here is my code:

public class MainActivity extends AppCompatActivity {

private Button upload;
private static final String ACCESS_TOKEN = "<ACCESS_TOKEN>";
//DbxRequestConfig config = new DbxRequestConfig("dropbox/java-tutorial");
DbxRequestConfig config = DbxRequestConfig.newBuilder("dropbox/java-tutorial")
.withHttpRequestor(OkHttp3Requestor.INSTANCE)
.build();
DbxClientV2 client = new DbxClientV2(config, ACCESS_TOKEN);
private String outputFile = null;


@Override
protected void onCreate(Bundle savedInstanceState) {
ActivityCompat.requestPermissions(MainActivity.this, new String[] {android.Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);


upload = (Button)findViewById(R.id.button);
upload.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {




File patternDirectory = new File(Environment.getExternalStorageDirectory().getAbsolutePath().toString()+"/test.txt");
patternDirectory.mkdirs();
String filename = "test.txt";
outputFile = Environment.getExternalStorageDirectory() + "/test.txt";
String string = "Hello world!";
FileOutputStream outputStream;

try {
outputStream = new FileOutputStream(new File(patternDirectory.getAbsolutePath().toString()+"/test.txt"),true);
outputStream.write(string.getBytes());
outputStream.close();
} catch (Exception e) {
System.out.println("Creating file not working");
e.printStackTrace();
}



try {
InputStream in = new FileInputStream(patternDirectory.getAbsolutePath().toString()+"/test.txt");
FileMetadata metadata = client.files().uploadBuilder("/test.txt").uploadAndFinish(in);

} catch (Exception e) {
System.out.println("Upload file not working");
e.printStackTrace();
}
}
});
}

}

 

 

 

 

1 Accepted Solution

Accepted Solutions

Greg-DB
Dropbox Staff
Go to solution
This error indicates that your OAuth 2 access token is incorrect, i.e., it doesn't match the expected pattern.

In the code you shared in your first post in this thread, you have your access token being saved to the variable ACCESS_TOKEN. It appears you redacted the value as "<ACCESS_TOKEN>" for the sake of posting it here, but make sure that the actual access token in your real code is valid, e.g., that you don't have any stray whitespace, etc.

View solution in original post

5 Replies 5

Greg-DB
Dropbox Staff
Go to solution
Do you have android.permission.INTERNET set for your app?

kestites
Explorer | Level 4
Go to solution
I don't think so.. how would I do that?

kestites
Explorer | Level 4
Go to solution

Okay I did that, but now I am getting this error:

W/System.err: com.dropbox.core.BadRequestException: Error in call to API function "files/upload": The given OAuth 2 access token is malformed.
W/System.err: at com.dropbox.core.DbxRequestUtil.unexpectedStatus(DbxRequestUtil.java:287)
W/System.err: at com.dropbox.core.DbxUploader.finish(DbxUploader.java:223)
W/System.err: at com.dropbox.core.DbxUploader.uploadAndFinish(DbxUploader.java:101)
W/System.err: at com.dropbox.core.v2.DbxUploadStyleBuilder.uploadAndFinish(DbxUploadStyleBuilder.java:92)
W/System.err: at com.example.kestites.exportdatabase.MainActivity$1.onClick(MainActivity.java:94)
W/System.err: at android.view.View.performClick(View.java:5198)
W/System.err: at android.view.View$PerformClick.run(View.java:21147)
W/System.err: at android.os.Handler.handleCallback(Handler.java:739)
W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95)
W/System.err: at android.os.Looper.loop(Looper.java:148)
W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5417)
W/System.err: at java.lang.reflect.Method.invoke(Native Method)
W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

Greg-DB
Dropbox Staff
Go to solution
This error indicates that your OAuth 2 access token is incorrect, i.e., it doesn't match the expected pattern.

In the code you shared in your first post in this thread, you have your access token being saved to the variable ACCESS_TOKEN. It appears you redacted the value as "<ACCESS_TOKEN>" for the sake of posting it here, but make sure that the actual access token in your real code is valid, e.g., that you don't have any stray whitespace, etc.
Need more support?