Description
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (go version
)?
Go version : 1.9.2
GoMobile version : b28c5379a52d34717fd23307abe34f933d42850a
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (go env
)?
Dev on Windows 10 x86_64
Run on Android 7.0 arm64
What did you do?
If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.
I wanna start a web server on my Android Phone, so I wrote a go package , here's the code:
package me
import (
"fmt"
"io"
"net/http"
"os"
)
var (
Path string
)
func Start(pkg string) {
go run(pkg)
}
func run(pkg string) {
Path = pkg
http.HandleFunc("/", home)
http.HandleFunc("/upload", upload)
http.ListenAndServe(":8090", nil)
}
func home(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, `<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<form action="/upload" enctype="multipart/form-data" method="post">
<input type="file" name="file">
<input type="submit" name="submit">
</form>
</body>
</html>`)
}
func upload(w http.ResponseWriter, r *http.Request) {
r.ParseMultipartForm(32 << 20)
file, handler, err := r.FormFile("file")
if err != nil {
fmt.Println(err)
return
}
defer file.Close()
fmt.Fprintf(w, "%v", handler.Header)
f, err := os.OpenFile(Path+handler.Filename, os.O_WRONLY|os.O_CREATE, 0666)
if err != nil {
fmt.Println(err)
return
}
defer f.Close()
io.Copy(f, file)
}
Then I build a me.aar file , using this command:
gomobile.exe bind --target=android/arm,android/arm64 me
Then I import me.aar file into my android project , and start the web server:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)== PackageManager.PERMISSION_GRANTED) {
Me.start("/sdcard/");
} else {
Log.v(TAG,"Permission is revoked");
ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.CAMERA}, 38);
}
}else {
Me.start("/sdcard/");
}
}
}
I gave it internet permission, write-external-storage permission.
Then I start my app, browse http://192.168.0.152:8090 on my PC , I saw the home page!
But when I upload a file that bigger than 32M to my phone , it failed.
(Files that smaller than 32M works great )
What did you expect to see?
Uploading a file that bigger than 32M to my phone succeed.
What did you see instead?
I upload a file that bigger than 32M to my phone , it failed.