You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.

Forum Discussion

kestites's avatar
kestites
Explorer | Level 4
9 years ago

Permission Denied - Okhttp Dispatcher

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();
}
}
});
}

}

 

 

 

 

  • Greg-DB's avatar
    Greg-DB
    9 years ago
    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.

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

5,911 PostsLatest Activity: 20 minutes ago
333 Following

If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.

For more info on available support options for your Dropbox plan, see this article.

If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!