uploadcare / uploadcare-java

Java API client that handles uploads and further operations with files by wrapping Uploadcare Upload and REST APIs.
https://uploadcare.com
Apache License 2.0
5 stars 13 forks source link

AuthenticationException when calling copy #26

Closed baileyatwork closed 4 years ago

baileyatwork commented 4 years ago

Describe the bug

client.copyFile(cdnUrl, storageName) sometimes returns "successfully" (see #6. Yes, in this case, that error is still considered a successful call), but, more often than liked, it would return the following exception:

Exception in thread "main" com.uploadcare.exceptions.UploadcareAuthenticationException: <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>403: Forbidden</title>
<style>
body {
margin: 30px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
line-height: 1.6;
color: #666;
background: white;
max-width: 700px;
}
h3 { color: black }
a {
color: #00cf70;
text-decoration: none;
cursor: pointer;
}
a:hover { color: black }
code {
color: black;
font-size: 13px;
background: #f8f8f8;
border: solid 1px #e4e4e4;
padding: 2px 6px;
border-radius: 2px
}
</style>
</head>
<body>
<h3>Forbidden</h3>

<p>Can&#39;t access your storage. Please check permissions for bucket.</p>

<p>
See <a href="https://uploadcare.com/docs/delivery/">CDN documentation</a>
</p>

</body>
</html>

    at com.uploadcare.api.RequestHelper.checkResponseStatus(RequestHelper.java:246)
    at com.uploadcare.api.RequestHelper.executeQuery(RequestHelper.java:124)
    at com.uploadcare.api.Client.copyFile(Client.java:275)
    at Uploader.copyToStorage(Uploader.java:32)
    at UploadcareMain.main(UploadcareMain.java:31)

But there's no code changes nor bucket policy changes. Also, I can see the file via the Uploadcare CDN link.

In addition, auto-copying works, and I can see the images in my S3 bucket when I upload an image with that option turned on.

client.copyFile("https://ucarecdn.com/78c72b16-e92c-4fd1-9a68-4c487f85af77/-/sharp/15/", "my-storage-name"); or client.copyFile("78c72b16-e92c-4fd1-9a68-4c487f85af77", "my-storage-name");

Expected behavior

Return the error in #6 , which at least indicates that the call went through.

Code / screenshots

Environment

dmitry-mukhin commented 4 years ago

Is this intermittent behavior? Do some of the files make it to your bucket?

baileyatwork commented 4 years ago

This was intermittent when I opened this bug. But right now, it seems like it always fails. I also want to add that auto-copying works, and when I have it turned on, the files do get copied automatically to my S3 bucket when uploaded. However, that might not be the workflow that we want to go with.

dmitry-mukhin commented 4 years ago

We got to the bottom of this and this is not a bug after all. Turns out that target bucket settings that deny creation of new objects with public ACL are enforced here. So, either relax bucket settings to allow new public objects or send additional make_public=false param.