question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Upload DocumentFile to server

See original GitHub issue

Library version: 0.9.0 OS version: [Android 10] Device model: [Vivo v11 Pro]

Describe the bug Getting getAbsolutePath{} as blank but the name is there.

To Reproduce

implementation "com.anggrayudi:storage:0.9.0"

private lateinit var storage: SimpleStorageHelper

storage = SimpleStorageHelper(this)
	storage.onStorageAccessGranted = { _, root ->
		Toast.makeText(
			this,
			getString(
				R.string.ss_selecting_root_path_success_without_open_folder_picker,
				root.getAbsolutePath(this)
			),
			Toast.LENGTH_SHORT
		).show()
	}
		
storage.onFileSelected = { _, file ->
	Toast.makeText(baseContext, "File selected: ${file.fullName}", Toast.LENGTH_SHORT)
	.show()
	val fileLocation = file.getAbsolutePath(this@UploadDocument)
	logUtil.logV(">>>>> the name is : ${file.name}")
	logUtil.logV(">>>>> if file : ${file.isFile}")
	logUtil.logV(">>>>> the location : $fileLocation")
	gotFile(
		File(fileLocation)
	)
}

storage.openFilePicker(REQUEST_CODE_PICK_FILE, "image/*", "application/pdf")

Stacktrace

V: >>>>> the name is : IMG-20210712-WA0000.jpg
V: >>>>> if file : true
V: >>>>> the location : 

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
anggrayudicommented, May 9, 2022

You can read the file via InputStream:

storage.onFileSelected = { _, files: List<DocumentFile> ->
    files.first().openInputStream(context)?.use { stream ->
       // upload stream to the server in Base64 format
       // https://stackoverflow.com/q/42667942/3922207
    }
}
0reactions
anggrayudicommented, May 9, 2022
  • For file type, better use DocumentFile.type or DocumentFile.mimeTypeByFileName.
  • For file size, use DocumentFile.length() or DocumentFile.getFormattedSize()
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to get file from 'DocumentFile' and send that file to server ...
How to get file from 'DocumentFile' and send that file to server using retrofit ... createChooser(intent, "Select a File to Upload"), ...
Read more >
UPLOADING PDF FILE TO SERVER USING RETROFIT IN ...
This wrap up the the Android uploading media file to server using Retrofit. Pdf upload takes cognizance of the use of nbsp -...
Read more >
Upload Files To Server Using Retrofit 2 In Android - C# Corner
In this article, we will learn how to upload any file to an online server using Retrofit 2 in Android.
Read more >
coder/code-server - Document file uploading in FAQ - GitHub
Hi, I am using the code-server on my ububuntu azure host for some weeks now, but i have allot of local projects on...
Read more >
Simple File Upload - Server 2022 - Relativity Documentation
Simple File Upload, formerly Single File Upload, gives users the ability to add new documents to Relativity without using the Relativity Desktop Client....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found