Octet Stream Encoding

Posted on
Octet Stream Encoding Rating: 3,7/5 8393 reviews

Join GitHub today

GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.

Sign up New issue

When a Controller operation returns `byte[]` the content should automatically be set to `application/octet-stream` #7926.

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails. Childish gambino girlfriend.

Already on GitHub? Sign in to your account

Comments

commented Nov 9, 2017
edited

Hi, thank you for the amazing repo!

Instead of Content-Type: text/csv is it possible to set Content-Type as application/octet-stream for the attached csv files?

thank you
Radoslaw

commented Nov 9, 2017

Hey, thanks for posting. I'm not sure why you would want that :)? It would help understanding how it would fit in the code.

commented Nov 10, 2017

Thank you Pascal for your prompt reply. Based on my understanding all csv files send via yagmail are detected as 'Content-Type: text/csv; name='some_filename.csv' which is very nice feature because the content of the csv file is directly displayed inline in the body of the email.

But for my case I would like to display the attachments as the attachements. See the screenshot.

Thank you.
Have a wonderful weekend!
Radoslaw

commented Nov 11, 2017
edited

Hi Radoslaw, just a guess.. but are you mentioning the csv in contents or in attachments? In case you cannot get it to work with using attachments, it's most likely a bug. You too, enjoy the weekend :-)

commented Nov 11, 2017

Hi Pascal, yes I'm using attachments. See the code and zipped csv.

smtp.send(to=myemail, subject='test1', attachments='/path/123_ARIADNA-10-2017.csv' )
123_ARIADNA-10-2017.csv.zip

Thank you
Radoslaw

added a commit that referenced this issue Nov 11, 2017

commented Nov 11, 2017

Could you try to see if it works for you with yagmail-0.10.209?

commented Nov 11, 2017

No luck.

print(yagmail.__version__)
shows: 0.10.209
but I'm still getting the same results.

here are the raw content of the email:

commented Nov 11, 2017
edited

I think I misunderstood the question!

For me in gmail, the csv shows just fine (not inline, but as attachment). But you want application/octet-stream as type? Why? Isn't the type of a .csv file 'text/csv'?

commented Nov 12, 2017
edited

Yes it works on gmail web client.
The issue has something to do with the mac Mail App (desktop & ios)
If you have macOS or iPhone when you will see that the csv attachments are displayed inline.

See the part of the raw source, email send via perl's MIME::Lite + Net:SMTP, which works:

based on my research adding Content-Disposition: attachment with Content-Type: application/csv should work
in the meantime a small amendment in sender.py did the trick ;)

changed the titleContent-Type: application/octet-stream for the csv filesNov 12, 2017

commented May 4, 2018

Had the same problem, still a bug at v0.10.212. @radoslawoska fix works.
CSV attachments sent with yagmail can't be read properly on gmail client running on apple systems on current version. Its really important ^^.
cheers!

commented May 4, 2018

I have missed this one, thanks for bringing it back to attention. Feel free to make a PR as you've already found the fix, I'd gladly accept it and put it on pypi!

added a commit to amrutadotorg/yagmail that referenced this issue Nov 5, 2018

csv files proper handling in the Mac mail client
Verified
This commit was created on GitHub.com and signed with a verified signature using GitHub’s key.
GPG key ID: 4AEE18F83AFDEB23Learn about signing commits

referenced this issue Nov 5, 2018

Open

csv files proper handling in the Mac mail client #129

commented Nov 5, 2018

thank you, PR created

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment
-->

Various content types can flow through a logic app,for example, JSON, XML, flat files, and binary data.While Logic Apps supports all content types, some have nativesupport and don't require casting or conversion in your logic apps.Other types might require casting or conversion as necessary.This article describes how Logic Apps handles content types andhow you can correctly cast or convert these types when necessary.

To determine the appropriate way for handling content types,Logic Apps relies on the Content-Type header value in HTTP calls,for example:

  • application/json (native type)
  • text/plain (native type)

application/json

Octet Stream Encoding

Logic Apps stores and handles any request with the application/jsoncontent type as a JavaScript Notation (JSON) object.By default, you can parse JSON content without any casting.To parse a request that has a header with the 'application/json' content type,you can use an expression. This example returns the value dog from theanimal-type array without casting:

Ableton live. Ableton Live Suite 10 Serial Number is designed as a tool for composing, recording, arranging, mixing and mastering music. Ableton Live is widely used by DJ’s around the world to produce music of the highest quality because it is supported with excellent features as well.

@body('myAction')['animal-type'][0]

If you're working with JSON data that doesn't specify a header,you can manually cast that data to JSON by using thejson() function,for example:

@json(triggerBody())['animal-type']

Create tokens for JSON properties

Logic Apps provides the capability for you to generate user-friendlytokens that represent the properties in JSON content so you canreference and use those properties more easily in your logic app's workflow.

  • Request trigger

    When you use this trigger in the Logic App Designer, you can providea JSON schema that describes the payload you expect to receive.The designer parses JSON content by using this schema and generatesuser-friendly tokens that represent the properties in your JSON content.You can then easily reference and use those properties throughout yourlogic app's workflow.

    If you don't have a schema, you can generate the schema.

    1. In the Request trigger, select Use sample payload to generate schema.

    2. Under Enter or paste a sample JSON payload, provide a sample payloadand then choose Done. For example:

      The generated schema now appears in your trigger.

      Here is the underlying definition for your Request trigger in the code view editor:

    3. In your request, make sure you include a Content-Type headerand set the header's value to application/json.

  • Parse JSON action

    When you use this action in the Logic App Designer,you can parse JSON output and generate user-friendlytokens that represent the properties in your JSON content.You can then easily reference and use those propertiesthroughout your logic app's workflow. Similar tothe Request trigger, you can provide or generate aJSON schema that describes the JSON content you want to parse.That way, you can more easily consume data from Azure Service Bus,Azure Cosmos DB, and so on.

text/plain

When your logic app receives HTTP messages thathave the Content-Type header set to text/plain,your logic app stores those messages in raw form.If you include these messages in subsequent actions without casting,requests go out with the Content-Type header set to text/plain.

For example, when you're working with a flat file,you might get an HTTP request with the Content-Typeheader set to text/plain content type:

Date,Name,Address
Oct-1,Frank,123 Ave

If you then send this request on in a later action as the body for another request,for example, @body('flatfile'), that second request also has a Content-Typeheader that's set to text/plain. If you're working with data that is plain textbut didn't specify a header, you can manually cast that data to text by using thestring() functionsuch as this expression:

@string(triggerBody())

application/xml and application/octet-stream

Logic Apps always preserves the Content-Type in a received HTTP request or response.So if your logic app receives content with Content-Type set to application/octet-stream,and you include that content in a later action without casting,the outgoing request also has Content-Type set to application/octet-stream.That way, Logic Apps can guarantee that data doesn't get lost while moving through the workflow.However, the action state, or inputs and outputs, is stored in a JSON objectwhile the state moves through the workflow.

Converter functions

To preserve some data types, Logic Apps converts content to a binarybase64-encoded string with appropriate metadata that preserves boththe $content payload and the $content-type, which are automatically converted.

This list describes how Logic Apps converts content when you use thesefunctions:

  • json(): Casts data to application/json
  • xml(): Casts data to application/xml
  • binary(): Casts data to application/octet-stream
  • string(): Casts data to text/plain
  • base64(): Converts content to a base64 string
  • base64toString(): Converts a base64 encoded string to text/plain
  • base64toBinary(): Converts a base64 encoded string to application/octet-stream
  • encodeDataUri(): Encodes a string as a dataUri byte array
  • decodeDataUri(): Decodes a dataUri into a byte array

For example, if you receive an HTTP requestwhere Content-Type set to application/xml,such as this content:

You can cast this content by using the @xml(triggerBody())expression with the xml() and triggerBody() functionsand then use this content later. Or, you can use the@xpath(xml(triggerBody()), '/CustomerName') expressionwith the xpath() and xml() functions.

Other content types

Logic Apps works with and supports other content types,but might require that you manually get the messagebody by decoding the $content variable.

For example, suppose your logic app gets triggered by a requestwith the application/x-www-url-formencoded content type.To preserve all the data, the $content variable in therequest body has a payload that's encoded as a base64 string:

Octet

CustomerName=Frank&Address=123+Avenue

Because the request isn't plain text or JSON,the request is stored in the action as follows:

Logic Apps provides native functions for handling form data, for example:

Or, you can manually access the data by using an expression such as this example:

@string(body('formdataAction'))

If you wanted the outgoing request to have the sameapplication/x-www-url-formencoded content type header,you can add the request to the action's body withoutany casting by using an expression such as @body('formdataAction').However, this method only works when the body is the onlyparameter in the body input. If you try to use the@body('formdataAction') expression in an application/json request,you get a runtime error because the body is sent encoded.