首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >一个文件是如何通过多部分/表单数据上传的..。使用哪种格式- UTF8、Base64或任何其他格式

一个文件是如何通过多部分/表单数据上传的..。使用哪种格式- UTF8、Base64或任何其他格式
EN

Stack Overflow用户
提问于 2014-08-23 18:43:32
回答 1查看 1.4K关注 0票数 0

UTF8,base64格式

大家好,

这是我的问题..。我想了解当通过多部分/表单数据上传时,文件内容是如何或以何种格式传输给服务器的。

当我试图从我的serverAlfresco上传文件和几个params到codeSalesforce时,Apex和服务器似乎没有从我的请求中识别出任何一个。同时,当我试图使用任何REST客户端测试器上传时,我工作得很好,文档被上传到服务器中。

我设法在服务器端放置了一个嗅探器,并从Salesforce-Apex代码和REST客户端Tester跟踪传入的http数据包。两者似乎是相同的,静态服务器对REST客户端响应200 OK,对我的代码响应400不好的请求。

下面是从我的嗅探器中获取的示例跟踪,如字符串所示。我想知道以下HTTP请求的主体--即,以边界字符串开头的多部分/表单-数据是如何在导线中遍历的。

它是用字符串、Blob、UTF-8、Base64编码的还是格式的

有谁能给我提供同样的深度知识吗。关于这些格式,我发现很难理解这些格式到底是什么,以及这些格式是如何形成和解密的。

代码语言:javascript
复制
POST /alfresco/service/api/upload?alf_ticket=TICKET_f1fbae39901a12ce8e33a75b84b5931661f0acbb HTTP/1.0
SFDC_STACK_DEPTH: 1
User-Agent: SFDC-Callout/31.0
Accept: application/json
Content-Type: multipart/form-data; boundary=----WebKitFormBoundarynwLnClZSXCKQvu3H
Pragma: no-cache
Host: myAlfrescoServer:8080
Content-Length: 581
Via: 1.1 proxy-was.net.salesforce.com:8080 (squid)
X-Forwarded-For: 10.236.12.23
Cache-Control: no-cache, max-age=259200
Connection: keep-alive

------WebKitFormBoundarynwLnClZSXCKQvu3H
Content-Disposition: form-data; name="filename"

12.txt
------WebKitFormBoundarynwLnClZSXCKQvu3H
Content-Disposition: form-data; name="description"

PPPPPPPPP
------WebKitFormBoundarynwLnClZSXCKQvu3H
Content-Disposition: form-data; name="siteid"

edms
------WebKitFormBoundarynwLnClZSXCKQvu3H
Content-Disposition: form-data; name="containerid"

documentLibrary
------WebKitFormBoundarynwLnClZSXCKQvu3H
Content-Disposition: form-data; name="filedata"; filename="12.txt"
Content-Type: text/plain

123
------WebKitFormBoundarynwLnClZSXCKQvu3H-- 
EN

回答 1

Stack Overflow用户

发布于 2014-08-23 23:17:42

如果您需要解码服务器端的表单数据,那么您确实应该考虑使用您选择的语言中的相关帮助。在PHP中,即$_POST,在Java中,类似于文件的FileItem,或者Perl的CGI->param等等。

特别是,阿尔弗雷科的WebscriptServletRequest助手应该消除大部分的痛苦和它的声音,这是很好的工作对你。你为什么不通过你的嗅探器发送一个REST请求,并与Salesforce一号进行比较呢?你在你的Alfresco上犯了什么错误?

然而,对于您的信息,multipart/form-data是复杂的,但它的不足是它使用了7位

以下是进一步的解读:

  • http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.2
  • http://www.ietf.org/rfc/rfc2048.txt
  • http://www.ietf.org/rfc/rfc2045.txt

您可以在RFC2045第六节中找到相关部分:

代码语言:javascript
复制
6.1.  Content-Transfer-Encoding Syntax

The Content-Transfer-Encoding field's value is a single token
specifying the type of encoding, as enumerated below.  Formally:

 encoding := "Content-Transfer-Encoding" ":" mechanism

 mechanism := "7bit" / "8bit" / "binary" /
              "quoted-printable" / "base64" /
              ietf-token / x-token

These values are not case sensitive -- Base64 and BASE64 and bAsE64
are all equivalent.  An encoding type of 7BIT requires that the body
is already in a 7bit mail-ready representation.  This is the default
value -- that is, "Content-Transfer-Encoding: 7BIT" is assumed if the
Content-Transfer-Encoding header field is not present.
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25465231

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档