Loading image in Android as static server

I’m tryig to run GO server in my Android app, the app is running the camera,and saving files at:


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("", nil))

But once I tried to open the files saved there, after being taken from the camera, and I go to:

I’m getting the 404 page not found

Any thought?

This really excellent idea.
how you have done.
can you share the sample code

1 Like

I solved it, and sharing my files: here

  1. 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))
  1. 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