hyousef
(Hasan Yousef)
1
I’m tryig to run GO
server in my Android app, the app is running the camera,and saving files at:
file:///storage/emulated/0/Android/media/com.myapp/
I’m trying to define this bath as the static path in my server, as:
fsAndroid := http.FileServer(http.Dir("file:///storage/emulated/0/Android/media/com.myapp/"))
http.Handle("/android/", fsAndroid)
go func() {
log.Println(http.ListenAndServe("127.0.0.1:6060", nil))
<-c
}()
But once I tried to open the files saved there, after being taken from the camera, and I go to:
http://127.0.0.1:6060/android/myfile.jpg
I’m getting the 404 page not found
Any thought?
packs
(Prakash)
2
This really excellent idea.
how you have done.
can you share the sample code
1 Like
hyousef
(Hasan Yousef)
3
Sure:
I solved it, and sharing my files: here
- From Go, I used, thanks for fizzie note above:
fsAndroid := http.FileServer(http.Dir("/storage/emulated/0/")) // Pictures/tk.cocoon/
http.Handle("/android/", http.StripPrefix("/android/", fsAndroid))
- In Android, I used:
interface ImageUri {
companion object {
fun create() : Uri? {
// Create an image file name
val timeStamp = SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(Date())
Global.fileName = "IMG_${timeStamp}.jpg"
Global.filePath = "Pictures/tk.cocoon/IMG_${timeStamp}.jpg"
val resolver = Global.context.contentResolver
val contentValues = ContentValues().apply {
put(MediaStore.MediaColumns.DISPLAY_NAME, Global.fileName)
put(MediaStore.MediaColumns.MIME_TYPE, "image/jpeg")
//put(MediaStore.MediaColumns.RELATIVE_PATH, "Android/media/tk.cocoon/")
put(MediaStore.MediaColumns.RELATIVE_PATH, "Pictures/tk.cocoon/")
}
Global.photoURI = resolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, contentValues)
return Global.photoURI
}
}
}
packs
(Prakash)
4
How to run go code inside Android
packs
(Prakash)
5
How you call go server inside the android application ( java )
hyousef
(Hasan Yousef)
7
system
(system)
Closed
9
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.