where is the data of a file sent via file-multipart stored? - rest

When sending an image via Content-Type:multipart/form-data , I see this in my POST request body
------WebKitFormBoundaryBB26cXe41lTj0CmC
Content-Disposition: form-data; name="file"; filename="My file.jpeg"
Content-Type: image/jpeg
------WebKitFormBoundaryBB26cXe41lTj0CmC
Content-Disposition: form-data; name="fileName"
My file.jpeg
------WebKitFormBoundaryBB26cXe41lTj0CmC
Content-Disposition: form-data; name="fileSize"
2268401
------WebKitFormBoundaryBB26cXe41lTj0CmC
Content-Disposition: form-data; name="fileType"
image/jpeg
------WebKitFormBoundaryBB26cXe41lTj0CmC
Content-Disposition: form-data; name="fileLastMod"
Wed Oct 04 2017 18:09:55 GMT+0200 (CEST)
------WebKitFormBoundaryBB26cXe41lTj0CmC--
This obviously doen't contain all the info that makes My file.jpeg.
So where is the actual data that makes My file.jpeg stored in this request ?

The image data is clearly not there. It comes right after any headers. In your case it's Content-Type: image/jpeg. And it ends at the next boundary, in your case ------WebKitFormBoundaryBB26cXe41lTj0CmC

Related

How can I forward an email that contains a picture with smtplib?

My code only extracts text types in an email, and forwards the email.
My code:
msg=email.message_from_string(raw_email.decode('utf-8')) #raw_email = fetched[0][1]
content = ''
content_type = None
if msg.is_multipart():
for part in msg.walk():
if part.get_content_maintype() == 'text':
thispart = part.get_payload(decode=True)
if isinstance(thispart, bytes):
thispart = thispart.decode()
content = thispart
content_type = part.get_content_subtype()
else:
if msg.get_content_maintype() == 'text':
thispart = msg.get_payload()
if isinstance(thispart, bytes):
thispart = thispart.decode()
content = thispart
content_type = msg.get_content_subtype()
my_mail = email.message.EmailMessage()
my_mail.set_content(content)
But some emails contain pictures, so what I want more is to forward pictures also.
It comes like this:
Received: from [127.0.0.1] ()
by xxxx () with ESMTP id xxxx
for <xxx#xxx>; Wed, 27 May 2020 18:09:34 +0900
Content-Type: multipart/alternative;
boundary="--_NmP-ebdbfeeb1622aae7-Part_1"
X-FireEye: Clean
From: xxxx#xxxx
To: xxx#xxx
Subject: =?UTF-8?Q?XXXXX?=
Message-ID: <XXXXXX#XXX>
Date: Wed, 27 May 2020 09:09:34 +0000
MIME-Version: 1.0
----_NmP-ebdbfeeb1622aae7-Part_1
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
CONTENT Link </a><br>URL : <a =href></a><br><br><br>
----_NmP-ebdbfeeb1622aae7-Part_1
Content-Type: multipart/related; type="text/html";
boundary="--_NmP-ebdbfeeb1622aae7-Part_3"
----_NmP-ebdbfeeb1622aae7-Part_3
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
CONTENT Link </a><br>URL : <a =href></a><br><br><br> <img src=3D"cid:unique"/>
----_NmP-ebdbfeeb1622aae7-Part_3
Content-Type: image/png; name=image.png
Content-ID: <unique>
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=image.png
LOTS_OF_WIERD_CHARACTERS
----_NmP-ebdbfeeb1622aae7-Part_3--
----_NmP-ebdbfeeb1622aae7-Part_1--
This mail is multiparted, and there are lots of weird characters which seem to represent an image.
How can I create a multipart email that contains an image, and how can I represent that image with the received weird characters??
Thanks:)

Inline Images are Broken

I'm trying to send an email with an inline image. I've set the Content-ID and added a <img src="cid:image1#myemail"> to my html. The image arrives properly as an attachment, but mail clients show a broken image.
What am I doing wrong? The full source of the message is below:
Return-Path: <igal#lucee.org>
Received: from 128.149.80.230
by smtp.googlemail.com with ESMTPSA id i7sm9313707paf.9.2016.09.01.11.15.59
for <igal#lucee.org>
(version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128);
Thu, 01 Sep 2016 11:15:59 -0700 (PDT)
Date: Thu, 1 Sep 2016 11:15:54 -0700 (PDT)
From: igal#lucee.org
To: igal#lucee.org
Message-ID: <489410968.5.1472753755600.JavaMail.Admin#IS16>
Subject: [Test] LDEV-545 html 5.0.0.200
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="----=_Part_4_247149912.1472753754816"
X-Mailer: Lucee Mail
------=_Part_4_247149912.1472753754816
Content-Type: multipart/alternative;
boundary="----=_Part_3_913848408.1472753754815"
------=_Part_3_913848408.1472753754815
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Text Message
------=_Part_3_913848408.1472753754815
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 7bit
Inline Image: <img src="cid:image1#myemail">
------=_Part_3_913848408.1472753754815--
------=_Part_4_247149912.1472753754816
Content-Type: image/jpeg; name=test-image.jpg
Content-Transfer-Encoding: base64
Content-Disposition: inline; filename=test-image.jpg
Content-ID: image1#myemail
/9j/4AAQSkZJRgABAQEAYABgAAD/4QBoRXhpZgAATU0AKgAAAAgABAEaAAUAAAABAAAAPgEbAAUA
AAABAAAARgEoAAMAAAABAAIAAAExAAIAAAARAAAATgAAAAAAAABgAAAAAQAAAGAAAAABcGFpbnQu
bmV0IDQuMC4xMAAA/9sAQwAKBwcJBwYKCQgJCwsKDA8ZEA8ODg8eFhcSGSQgJiUjICMiKC05MCgq
NisiIzJEMjY7PUBAQCYwRktFPko5P0A9/9sAQwELCwsPDQ8dEBAdPSkjKT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09/8AAEQgAIgBDAwEiAAIRAQMRAf/E
AB8AAAEFAQEBAQEBAAAAAAAAAAABAgMEBQYHCAkKC//EALUQAAIBAwMCBAMFBQQEAAABfQECAwAE
EQUSITFBBhNRYQcicRQygZGhCCNCscEVUtHwJDNicoIJChYXGBkaJSYnKCkqNDU2Nzg5OkNERUZH
SElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6g4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1
tre4ubrCw8TFxsfIycrS09TV1tfY2drh4uPk5ebn6Onq8fLz9PX29/j5+v/EAB8BAAMBAQEBAQEB
AQEAAAAAAAABAgMEBQYHCAkKC//EALURAAIBAgQEAwQHBQQEAAECdwABAgMRBAUhMQYSQVEHYXET
IjKBCBRCkaGxwQkjM1LwFWJy0QoWJDThJfEXGBkaJicoKSo1Njc4OTpDREVGR0hJSlNUVVZXWFla
Y2RlZmdoaWpzdHV2d3h5eoKDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXG
x8jJytLT1NXW19jZ2uLj5OXm5+jp6vLz9PX29/j5+v/aAAwDAQACEQMRAD8A9mooqvNfQW95bWsj
kTXO7ylwfm2jJ57cU0m9gLFFUdK1qx1uGWXT5xMkUhif5SpDDtggetGnazY6sbkWM4l+yymGUgEB
WHXk9fqKt0pxveL038hcyL1FUdL1ix1mxN5YTrLbhmUvgjBHXrVaHxRpk80aRSzMkjiOOf7PJ5Ls
TgASbdpyenPNP2NS7XK9N9Ng5l3NeisuPxFZTXr2sK3cskc3kOyWkrIr9wXC7RjPXNalTKEofErA
mnsFFFFQMKwtX/5Gvw/9bj/0XW7RWlOfI7+TX3poTVzzLSGutB0y3uLBCzawJbUYHC3PnP5bn22s
2fZBV4xto9l4g03TR/pEs9vY22TglmgRdxPrjcxPtXfUV3SzDmk5OO++u+qav6JWMlSsrXOANlf2
iavpC2cdl/aViWtIYp/MG+NAjAHaOSu38iauyeI0a50eHSNRjRZJooJdOMI82Nf4s55XAGOldlij
AznHPrUPGRl8cP6tbqn2XnvrqP2bWzOK0C+trfXtTim1xLd31SULYsYx5pOADyN3J9D2rtqTFLXP
XrKrLmSt/Xoi4x5VYKKKKwKCiiigAooooAKKKKACiiigAooooA//2Q==
------=_Part_4_247149912.1472753754816--
I found the problem. It is missing Content-Type: multipart/related;

Titanium multipart file upload with different content types?

So I am trying to post to a Salesforce.com REST api that is expecting the following sample request -
POST /services/data/v33.0/chatter/feed-elements HTTP/1.1
Authorization: OAuth 00DRR0000000N0g!...
User-Agent: Jakarta Commons-HttpClient/3.0.1
Host: instance_name
Content-Length: 845
Content-Type: multipart/form-data; boundary=a7V4kRcFA8E79pivMuV2tukQ85cmNKeoEgJgq
Accept: application/json
--a7V4kRcFA8E79pivMuV2tukQ85cmNKeoEgJgq
Content-Disposition: form-data; name="json"
Content-Type: application/json; charset=UTF-8
{
"body":{
"messageSegments":[
{
"type":"Text",
"text":"Please accept this receipt."
}
]
},
"capabilities":{
"content":{
"description":"Receipt for expenses",
"title":"receipt.pdf"
}
},
"feedElementType":"FeedItem",
"subjectId":"005RR000000DmOb"
}
--a7V4kRcFA8E79pivMuV2tukQ85cmNKeoEgJgq
Content-Disposition: form-data; name="feedElementFileUpload"; filename="receipt.pdf"
Content-Type: application/octet-stream; charset=ISO-8859-1
...contents of receipt.pdf...
--a7V4kRcFA8E79pivMuV2tukQ85cmNKeoEgJgq--
As you can see, the two parts of the request is expecting different content types.
In Titanium, I have the following code -
xhr.open("POST", postUri);
xhr.setRequestHeader("Authorization", authHeader);
xhr.setRequestHeader('enctype', 'multipart/form-data');
var data2send = {
json: jsonObj,
feedElementFileUpload: imageBlob
};
xhr.send(data2send);
According to the Appcelerator documentation and a couple of online threads, the httpclient should be able to set each part automatically, however, Salesforce API still gives an error message of:
[{"errorCode":"MISSING_ARGUMENT","message":"Missing required 'subjectId' parameter."}]
I can confirm that subjectId is in the jsonObj and its content is correct. It seems that the json part is not recognised as JSON by Salesforce correctly. How can I set the content-type correctly? Many thanks.
Updates - I used the Wireshark to capture the request text. Apparently the httpclient did not set up the content-type for the json part that Salsforce API is expecting. Any idea how to set it?
POST /services/data/v33.0/chatter/feed-elements HTTP/1.1
Host: mydomain.com
Accept-Language: en-us
User-Agent: Appcelerator Titanium/3.5.1 (iPhone Simulator/8.2; iPhone OS; en_US;)
enctype: multipart/form-data
X-Requested-With: XMLHttpRequest
Accept: */*
Content-Type: multipart/form-data; charset=utf-8; boundary=0xTibOuNdArY_1430987526
Connection: keep-alive
Authorization: Bearer $My_AUTH_CODE
X-Titanium-Id: 8329dd1d-3379-4d7c-955e-120ad1586a2b
Content-Length: 93333
Accept-Encoding: gzip, deflate
--0xTibOuNdArY_1430987526
Content-Disposition: form-data; name="json"
{"feedElementType":"FeedItem","subjectId":"xxxxxxxxxx","body":{"messageSegments":[{"type":"text","text":"test"}]},"capabilities":{"content":{"description":"sdfaadfs","title":"adsfafsd.png"}}}
--0xTibOuNdArY_1430987526
Content-Disposition: form-data; name="feedElementFileUpload"; filename="01430987526.png"
Content-Type: image/png
my file data...

InvalidParameterValue: Duplicate header 'Content-Type' when send RawMessage with Amazon SES

I'm trying to send a raw email message with Amazon SES API to include attachment.
SES reponse with 400 status code and I not sure what I'm doing wrong, here is the response:
<ErrorResponse xmlns="http://ses.amazonaws.com/doc/2010-12-01/">
<Error>
<Type>Sender</Type>
<Code>InvalidParameterValue</Code>
<Message>Duplicate header 'Content-Type'.</Message>
</Error>
<RequestId>ad8cb17c-a8a0-11e4-8898-8924aa87abfa</RequestId>
</ErrorResponse>
The request signed and work OK with other request, so I think it must only my email message issue. Here is my message data:
Cc: my-verified-email-1#gmail.com
Subject: Hello testing email hahahahaha
Mime-Version: 1.0
Date: 30 Jan 15 23:54 +0700
Content-Type: multipart/mixed; boundary=7f1a313ee430f85a8b054f085ae67abd6ee9c52aa8d056e7f7e19c6e2887
From: my-verified-email-2#gmail.com
To: my-verified-email-3#gmail.com
--7f1a313ee430f85a8b054f085ae67abd6ee9c52aa8d056e7f7e19c6e2887
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Hello <b>testing email</b> with some =E4=B8=96=E7=95=8C and Vi=E1=BB=87t ng=
=E1=BB=AF.
--7f1a313ee430f85a8b054f085ae67abd6ee9c52aa8d056e7f7e19c6e2887
Content-Type: text/plain; charset=utf-8; name="test1.txt"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="test1.txt"
dGVzdGluZyBzdHJpbmcgd2l0aCBWaeG7h3Qgbmfhu68K
--7f1a313ee430f85a8b054f085ae67abd6ee9c52aa8d056e7f7e19c6e2887--
OK, I just figure out that I was missing a new line before the first boundary line. The message should instead be:
Cc: my-verified-email-1#gmail.com
Subject: Hello testing email hahahahaha
Mime-Version: 1.0
Date: 30 Jan 15 23:54 +0700
Content-Type: multipart/mixed; boundary=7f1a313ee430f85a8b054f085ae67abd6ee9c52aa8d056e7f7e19c6e2887
From: my-verified-email-2#gmail.com
To: my-verified-email-3#gmail.com
--7f1a313ee430f85a8b054f085ae67abd6ee9c52aa8d056e7f7e19c6e2887
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Hello <b>testing email</b> with some =E4=B8=96=E7=95=8C and Vi=E1=BB=87t ng=
=E1=BB=AF.
--7f1a313ee430f85a8b054f085ae67abd6ee9c52aa8d056e7f7e19c6e2887
Content-Type: text/plain; charset=utf-8; name="test1.txt"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="test1.txt"
dGVzdGluZyBzdHJpbmcgd2l0aCBWaeG7h3Qgbmfhu68K
--7f1a313ee430f85a8b054f085ae67abd6ee9c52aa8d056e7f7e19c6e2887--

Jasper webservice: Invalid resource descriptor

I try to upload a simple image via REST webservice to the jasper server.
This is the HTTP request/response, I'm getting "400 Bad Request: Invalid resource descriptor".
I tried to copy a valid resource descriptor from the repository and re-upload it but it gives the same error!
(The dots represent \r\n and \t chars.)
T 10.84.6.166:36057 -> 10.84.6.166:8080 [AP].
PUT /jasperserver/rest/resource/reports/Customers/3221/image01.gif HTTP/1.1.
User-Agent: useragent.
Host: 10.84.6.166:8080.
Accept: */*.
Cookie: JSESSIONID=5D8D24835E61ED65ABD982964243C06B.
Content-Type: multipart/form-data; boundary="72e01e9922f8bb1669638258c2a2a155".
Content-Length: 23796.
Expect: 100-continue.
.
T 10.84.6.166:8080 -> 10.84.6.166:36057 [AP]
HTTP/1.1 100 Continue.
.
T 10.84.6.166:36057 -> 10.84.6.166:8080 [AP]
--72e01e9922f8bb1669638258c2a2a155.
Content-Disposition: form-data; name="ResourceDescriptor".
Content-Length: 811.
Content-Type: text/plain; charset=UTF-8.
Content-Transfer-Encoding: 8bit.
.
<resourceDescriptor name="s2" wsType="img" uriString="/reports/Customers/3221/s2.png" isNew="true">.
.<label><![CDATA[serverattacks_13-06-01.png]]></label>.
.<creationDate>1373470272965</creationDate>.
.<resourceProperty name="PROP_RESOURCE_TYPE">.
..<value><![CDATA[com.jaspersoft.jasperserver.api.metadata.common.domain.FileResource]]></value>.
.</resourceProperty>.
.<resourceProperty name="PROP_PARENT_FOLDER">.
..<value><![CDATA[/reports/Customers/3221]]></value>.
.</resourceProperty>.
.<resourceProperty name="PROP_VERSION">.
..<value><![CDATA[0]]></value>.
.</resourceProperty>.
.<resourceProperty name="PROP_HAS_DATA">.
..<value><![CDATA[true]]></value>.
.</resourceProperty>.
.<resourceProperty name="PROP_IS_REFERENCE">.
..<value><![CDATA[false]]></value>.
.</resourceProperty>.
</resourceDescriptor>.
--72e01e9922f8bb1669638258c2a2a155.
Content-Disposition: form-data; name="/reports/Customers/3221/s2.png".
Content-Length: 22544.
Content-Type: application/octet-stream.
Content-Transfer-Encoding: binary.
.
<long binary png contents>
--72e01e9922f8bb1669638258c2a2a155--.
T 10.84.6.166:8080 -> 10.84.6.166:36057 [AP]
HTTP/1.1 400 Bad Request.
Server: Apache-Coyote/1.1.
Pragma: No-cache.
Cache-Control: no-cache.
Expires: Thu, 01 Jan 1970 01:00:00 CET.
P3P: CP="ALL".
Content-Type: text/xml;charset=UTF-8.
Content-Length: 27.
Date: Thu, 11 Jul 2013 08:42:09 GMT.
Connection: close.
.
Invalid resource descriptor
Update:
I still don't know what's wrong but I finally got it working and released a Jasper PHP Library on github: http://blog.flowl.info/2013/jasper-php-library-on-github/
I tried to update jrxml on jasperServer. I found and buld java tests. I found working example of updating image on JasperServer.Mаy it is help уou.(With help of this example i wrote request for updating jrxml on jasperServer. And it is works!)
POST http://repsuite.cheby.ru:8080/jasperserver/rest/resource/SAMPLE_REST_FOLDER/JUNIT_IMAGE_FILE HTTP/1.1
Content-Length: 5560
Content-Type: multipart/form-data; boundary=dzFSpJmyJB0pL6bHxKgtqI4VmaKgL9pTWCrLeJv
Host: repsuite.cheby.ru:8080
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
Cookie: JSESSIONID=E485652B97C69549403D8CEEA0DC0855
Cookie2: $Version=1
--dzFSpJmyJB0pL6bHxKgtqI4VmaKgL9pTWCrLeJv
Content-Disposition: form-data; name="ResourceDescriptor"
<resourceDescriptor name="JUNIT_IMAGE_FILE" wsType="img" uriString="/SAMPLE_REST_FOLDER/JUNIT_IMAGE_FILE" isNew="true">
<label>jaspersoft logo</label>
<description>jaspersoft logo</description>
<creationDate>1308696383000</creationDate>
<resourceProperty name="PROP_RESOURCE_TYPE">
<value>com.jaspersoft.jasperserver.api.metadata.common.domain.FileResource</value>
</resourceProperty>
<resourceProperty name="PROP_PARENT_FOLDER">
<value>/SAMPLE_REST_FOLDER</value>
</resourceProperty>
<resourceProperty name="PROP_VERSION">
<value>0</value>
</resourceProperty>
<resourceProperty name="PROP_IS_REFERENCE">
<value>false</value>
</resourceProperty>
<resourceProperty name="PROP_HAS_DATA">
<value>true</value>
</resourceProperty>
</resourceDescriptor>
--dzFSpJmyJB0pL6bHxKgtqI4VmaKgL9pTWCrLeJv
Content-Disposition: form-data; name="/SAMPLE_REST_FOLDER/JUNIT_IMAGE_FILE"; filename="jasperSoftLogo_2.jpg"
Content-Type: application/octet-stream
----Binary content of image----