Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix chunk uploads #993

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Fix chunk uploads #993

wants to merge 3 commits into from

Conversation

byawitz
Copy link
Member

@byawitz byawitz commented Oct 2, 2024

What does this PR do?

Fix chunk uploads with predefined ID for

  • Kotlin (android)
  • Ruby

Test Plan

Running these code snippets.

Kotlin

val client = Client()
    .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
    .setProject("...")
    .setKey("...");

val s = Storage(client)
val response = s.createFile(
    bucketId = "...",
    fileId = ID.unique(),
    file = InputFile.fromPath("aaa.mp4"),
)

Ruby

client = Client.new
               .set_endpoint('https://cloud.appwrite.io/v1') # Your API Endpoint
               .set_project('...') # Your project ID
               .set_key('...') # The user session to authenticate with

storage = Storage.new(client)

result = storage.create_file(
  bucket_id: '...',
  file_id: ID.unique,
  file: InputFile.from_path('aaa.mp4'),
)

aaa.mp4 is bigger than 10MB.

Related PRs and Issues

#963

Have you read the [Contributing Guidelines on issues]

Yes

Copy link
Contributor

@stnguyen90 stnguyen90 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we rely on the error type instead of the error message?

val chunksUploaded = current["chunksUploaded"] as Long
offset = chunksUploaded * CHUNK_SIZE
} catch (e: Exception) {
if (e.message != null && !e.message!!.contains("file could not be found")) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with Steven, this seems fragile...

offset = chunksUploaded * CHUNK_SIZE
} catch (e: Exception) {
if (e.message != null && !e.message!!.contains("file could not be found")) {
throw e
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't call() methods already throw these exceptions, is there any need to catch and throw here?

@@ -304,13 +308,13 @@ module {{ spec.title | caseUcfirst }}
when Hash then value.map { |k,v| encode(v, append_key(key,k)) }.join('&')
when Array then value.map { |v| encode(v, "#{key}[]") }.join('&')
when nil then ''
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated, but can we fix the spacing here? Looks weird

params = emptyMap(),
responseType = Map::class.java,
)
val chunksUploaded = current["chunksUploaded"] as Long
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is Long type the best choice?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants