GAE 앱에 파일을 업로드하려고합니다. Go를 사용하고 r.FormValue()
을 사용하여 Google App Engine에서 파일을 업로드하려면 어떻게해야합니까?GAE에 파일 업로드
답변
중간 반환 매개 변수 인 "기타"를 사용하여 문제를 해결할 수있었습니다. 다음이 코드는
blobs, other, err := blobstore.ParseUpload(r)
그런 다음 formkey에게
file := blobs["file"]
**name := other["name"]** //name is a form field
**description := other["description"]** //descriptionis a form field
해당 할당하고 내 구조체의 값 할당이 같은이가있다
newData := data{
Name: **string(name[0])**,
Description: **string(description[0])**,
Image: string(file[0].BlobKey),
}
datastore.Put(c, datastore.NewIncompleteKey(c, "data", nil), &newData)
100 % 확인을 사용하는 업로드 핸들러 내부에 옳은 일이지만 내 문제를 해결하고 이미지를 BLOBSTORE에 업로드하고 다른 데이터와 BLOB 키를 데이터 저장소에 저장합니다.
다른 사람들에게도 도움이 될 수 있기를 바랍니다.
** **는 코드의 일부가 아닌 강조만을 의미합니다. – sagit
아이디어를 얻으려면 Blobstore Go API Overview을 사용해야하며 &을 Google App Engine에 Go를 사용하여 저장하는 방법은 full example입니다.
완전히 별도의 응용 프로그램에서이 예제를 수행 할 것을 제안합니다. 따라서 기존 예제와 통합하기 전에 잠깐 실험 해 볼 수 있습니다.
여기에서 전체 예제를 시도했습니다. https://developers.google.com/appengine/docs/go/blobstore/overview, 그리고 blobstore에서 업로드를 수행하고 잘 처리했습니다.
그러나 데이터 저장소의 어딘가에 저장 될 추가 게시물 값을 삽입하면 "r.FormValue()"값이 지워 집니까? 아래 코드를 참조하십시오.
func handleUpload(w http.ResponseWriter, r *http.Request) {
c := appengine.NewContext(r)
//tried to put the saving in the datastore here, it saves as expected with correct values but would raised a server error.
blobs, _, err := blobstore.ParseUpload(r)
if err != nil {
serveError(c, w, err)
return
}
file := blobs["file"]
if len(file) == 0 {
c.Errorf("no file uploaded")
http.Redirect(w, r, "/", http.StatusFound)
return
}
// a new row is inserted but no values in column name and description
newData:= data{
Name: r.FormValue("name"), //this is always blank
Description: r.FormValue("description"), //this is always blank
}
datastore.Put(c, datastore.NewIncompleteKey(c, "Data", nil), &newData)
//the image is displayed as expected
http.Redirect(w, r, "/serve/?blobKey="+string(file[0].BlobKey), http.StatusFound)
}
일반 데이터와 업로드를 결합 할 수 있습니까? r.FormValue()의 값이 파일 (입력 파일 유형)을 제외하고 사라지는 것처럼 보이는 이유는 무엇입니까? 업로드 결과로 blobkey를 다른 데이터에 연결하기 전에 먼저 업로드를 강제해야만한다고해도 업로드 처리기에 r.FormValue()를 전달할 수 없으므로 불가능합니다 (이는 내가 말했던 것처럼 비어 있거나, blob, _, err : = blobstore.ParseUpload (r) 문)보다 먼저 액세스 할 때 오류가 발생합니다. 누군가가이 문제를 해결할 수 있기를 바랍니다. 고맙습니다!
Blobstore API를 사용하는 것 외에도 Request.FormFile()
메서드를 사용하여 파일 업로드 콘텐츠를 가져올 수 있습니다. 추가 도움말을 보려면 net\http 패키지 설명서를 사용하십시오.
요청을 직접 사용하면 업로드 POST 메시지를 처리하기 전에 blobstore.UploadUrl()
설정을 건너 뛸 수 있습니다.
간단한 예는 다음과 같습니다
func uploadHandler(w http.ResponseWriter, r *http.Request) {
// Create an App Engine context.
c := appengine.NewContext(r)
// use FormFile()
f, _, err := r.FormFile("file")
if err != nil {
c.Errorf("FormFile error: %v", err)
return
}
defer f.Close()
// do something with the file here
c.Infof("Hey!!! got a file: %v", f)
}
- 1. android를 통해 GAE에 파일 업로드
- 2. 간단한 web2py 앱을 GAE에 업로드
- 3. Django의 admin 인터페이스를 사용하여 GAE에 큰 파일 업로드
- 4. multipart/form-data Flash에서 GAE에 파일 업로드 요청이 누락되었습니다.
- 5. Play로 GAE에 파일 업로드하기! 프레임 워크
- 6. Gae에 큰 Zip 파일 만들기 (블롭 스토어에서)
- 7. 처음 GAE에 관한 이야기
- 8. 파일 업로드 및 세션 또는 DB에 저장
- 9. HTML없이 GAE에 index.py 검색?
- 10. GAE에 레일 퍼팅 앱
- 11. GAE에 애플리케이션 배포
- 12. NetBeans를 사용하여 GAE에 연결
- 13. GAE에 워드 프레스 -
- 14. GAE에 로그인 Facebook 앱
- 15. Symfony2 : 파일 업로드 플러그인을 사용하여 파일 업로드
- 16. 풍부한 : 파일 업로드 : 파일 업로드 ViewExpiredException
- 17. Blueimp 파일 업로드 : 단일 파일 업로드
- 18. 이미지 파일 업로드 - 파일 업로드 오류 없음
- 19. jQuery 파일 업로드 - 양식에 파일 업로드
- 20. PHP 컬 파일 업로드 버튼이있는 파일 업로드
- 21. 파일 업로드 파일
- 22. 파일 형식으로 파일 업로드
- 23. CodeIgniter의 파일 업로드 파일
- 24. 파일 시스템에 파일 업로드
- 25. 사용자 파일 업로드 파일
- 26. Symfony 파일 (업로드 파일)
- 27. 파일 (서블릿에서 파일 업로드)
- 28. 파일 서버에 파일 업로드
- 29. 파일 변경시 파일 업로드
- 30. 업로드 파일
을 시도한 것을 볼 것이 좋을 것이다. –