简体   繁体   English

指定上传文件的实际内容类型

[英]Specify actual content-type of a uploaded file

I'm working on a blob upload service and I have this code that persist uploaded meta-data in the Datastore and the actual bytes into the Blobstore. 我正在使用Blob上传服务,并且我有这段代码可以将上传的元数据持久保存在数据存储区中,并将实际字节持久存储到Blob存储区中。

I am having issues with the Mime-Type provided by the REST client (I am using the Rest Console Chrome plugin) REST客户端提供的Mime-Type出现问题(我使用的是Rest Console Chrome插件)

This is the mime-type that is passed from the client to the server: 这是从客户端传递到服务器的mime类型:

Mime type:  multipart/form-data; boundary=----WebKitFormBoundarytxCVEFIRjPB7YIq7

However the server needs to get the "actual mime-type", that is, for example image/jpeg, image/jpeg, text/plain, etc. 但是,服务器需要获取“实际的mime类型”,例如image / jpeg,image / jpeg,text / plain等。

Using the App Engine API I need to explicitly provide the mime-type like this: 使用App Engine API,我需要像下面这样显式提供mime类型:

AppEngineFile file = fileService.createNewBlobFile(entity.getMimeType());

How do I specify this? 我该如何指定? Do I need to put another header? 我是否需要放置另一个标题? The files that will be uploaded will vary and that the file can be up to 50MB in size (If I remember that correctly). 将要上传的文件会有所不同,并且文件的大小最大为50MB(如果我没记错的话)。

"Multipart" means that the data sent can have multiple parts, each with it's own mime type. “多部分”表示发送的数据可以包含多个部分,每个部分都有自己的mime类型。 Read about handling multipart form uploads on GAE. 了解有关在GAE 上处理分段表格上传的信息。

You can use FileItemStream.getContentType() to get mime type of each part. 您可以使用FileItemStream.getContentType()获取每个部分的mime类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM