Skip to content
New issue

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.

Already on GitHub? Sign in to your account

Adding extension for attachments #7

Open
wants to merge 67 commits into
base: master
Choose a base branch
from
Open
Changes from 22 commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
f02c935
Create attachment.md
glennblock Oct 12, 2014
b391e7c
Update attachment.md
glennblock Oct 12, 2014
0eced3d
Update attachment.md
glennblock Oct 12, 2014
e3b92e8
Update attachment.md
glennblock Oct 12, 2014
63b03e3
Update attachment.md
glennblock Oct 12, 2014
e93235b
Update attachment.md
glennblock Oct 12, 2014
6dda53c
Update attachment.md
glennblock Oct 12, 2014
c3b93a9
Update attachment.md
glennblock Oct 12, 2014
039d474
Update attachment.md
glennblock Oct 12, 2014
69a8356
Update attachment.md
glennblock Oct 12, 2014
c2e5850
Update attachment.md
glennblock Oct 12, 2014
1be8395
Update attachment.md
glennblock Oct 12, 2014
520087b
Update attachment.md
glennblock Oct 12, 2014
9a7552d
Update attachment.md
glennblock Oct 12, 2014
e1e5030
Update attachment.md
glennblock Oct 12, 2014
d0938f3
Update attachment.md
glennblock Oct 12, 2014
fb64e28
Update attachment.md
glennblock Oct 12, 2014
51c14a0
Update attachment.md
glennblock Oct 12, 2014
0bfb4cc
Update attachment.md
glennblock Oct 12, 2014
408f82c
Update attachment.md
glennblock Oct 12, 2014
a981729
Update attachment.md
glennblock Oct 12, 2014
a2c0630
Update attachment.md
glennblock Oct 12, 2014
6a8f54d
Update attachment.md
glennblock Oct 12, 2014
721d14a
Update attachment.md
glennblock Oct 12, 2014
e93abb5
Update attachment.md
glennblock Oct 12, 2014
2215c4d
Update attachment.md
glennblock Oct 13, 2014
f6417da
Update attachment.md
glennblock Oct 13, 2014
bcd8749
Update attachment.md
glennblock Oct 13, 2014
8fc28a1
Update attachment.md
glennblock Oct 13, 2014
982693c
Update attachment.md
glennblock Oct 13, 2014
bcc4eef
Update attachment.md
glennblock Oct 13, 2014
b30afd3
Update attachment.md
glennblock Oct 13, 2014
097cc05
Update attachment.md
glennblock Oct 13, 2014
638e034
Update attachment.md
glennblock Oct 13, 2014
226dda9
Update attachment.md
glennblock Oct 13, 2014
0ed24f4
Updating details for live example
glennblock Oct 15, 2014
ac7a3bd
Update attachment.md
glennblock Oct 15, 2014
b2289c0
Update attachment.md
glennblock Oct 15, 2014
98976f5
Update attachment.md
glennblock Oct 16, 2014
68a46e2
Update attachment.md
glennblock Oct 16, 2014
b77b683
Update attachment.md
glennblock Oct 16, 2014
afd4a7f
Update attachment.md
glennblock Oct 16, 2014
1c50b87
Update attachment.md
glennblock Oct 16, 2014
ced21ae
Update attachment.md
glennblock Oct 16, 2014
9551375
Update attachment.md
glennblock Oct 16, 2014
ca93e81
Update attachment.md
glennblock Oct 16, 2014
09f24dc
Update attachment.md
glennblock Oct 16, 2014
b069860
Update attachment.md
glennblock Oct 16, 2014
82720a7
Update attachment.md
glennblock Oct 16, 2014
db25065
Update attachment.md
glennblock Oct 16, 2014
e22accb
Update attachment.md
glennblock Oct 16, 2014
b74332d
Update attachment.md
glennblock Oct 16, 2014
96eddfc
Update attachment.md
glennblock Oct 16, 2014
154886b
Update attachment.md
glennblock Oct 16, 2014
f49e75a
Update attachment.md
glennblock Oct 16, 2014
9bb8c4b
Update attachment.md
glennblock Oct 16, 2014
06868bb
Update attachment.md
glennblock Oct 16, 2014
6a79d1b
Update attachment.md
glennblock Oct 16, 2014
3a949cd
Update attachment.md
glennblock Oct 16, 2014
b87e14e
Update attachment.md
glennblock Oct 16, 2014
4b2c6ac
Update attachment.md
glennblock Oct 16, 2014
a39f626
Update attachment.md
glennblock Oct 16, 2014
b8179bb
Update attachment.md
glennblock Oct 16, 2014
7446176
Update attachment.md
glennblock Oct 16, 2014
e054a5b
Update attachment.md
glennblock Oct 16, 2014
688db86
Update attachment.md
glennblock Oct 16, 2014
d233882
Update attachment.md
glennblock Oct 16, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 117 additions & 0 deletions attachment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# Attachment extension
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very small nit. I'd like to use the abbreviation for collection+json as Cj, not CJ

This document outlines an extension which supports sending and receiving collection+json documents containing file attachments. This approach uses a multipart/form-data request / multipart/mixed response as a means of transfering attachments back and forth.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drop reference to multipart/mixed.


*Note*: Each of the examples below is based on the existing CJ friends [example](http://amundsen.com/media-types/collection/examples/).

It is inspired by this [discussion](https://groups.google.com/forum/#!topic/collectionjson/pzdkNGx-aPE)

The following RFCs form the basis of the approach in this document:

* [1341] (http://www.w3.org/Protocols/rfc1341/7_2_Multipart.html) - The Multipart Content-Type
* [2388] (http://tools.ietf.org/html/rfc2388) - Returning Values from Forms: multipart/form-data
* [6266] (http://tools.ietf.org/html/rfc6266) - Use of the Content-Disposition Header Field in the Hypertext Transfer Protocol (HTTP)

## Write template
A client may receive a CollectionJson document containing a Write template which accepts attachments which the client can use to send files.

### Attachment field
A new _attachment_ field is introduced on the data element. For a template, this indicates that this data element is an attachment. The value of the attachment is the mime type that is expected.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@glennblock : what if more than one mime type is possible? what if any type is possible?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For multiple mime types how about accepting a delimited list? This then raises a question of ranges like "image/*". As I think more through this you should probably be allowed to pass a delimited list of media types or ranges.

As for any type, if we accept ranges like "*" that would allow that.


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drop the above two lines as they are covered in the previous mods, right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a line defining the new value for the existing render property of a link object. use the above text as a guide.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • if the attachment property is missing, the client SHOULD treat the data element as a text element.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The attachment property is only for templates so why do I need to even mention this? If there's no attachment property by default it would just be treated as a standard template prop.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, it should read:

"if the attachment property is missing or set to a value to client does not understand, the client SHOULD treat the data element as a text element."

this is to cover future cases where there may be other values for attachment or there are changes to the contentType property.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So you mean in the cases where contentType is present and set to
multipart/form-data but no attachments are present?

On Wednesday, October 15, 2014, Mike Amundsen [email protected]
wrote:

In attachment.md:

+A client MAY receive a CollectionJson document containing a Write template which accepts attachments which the client can use to send files.
+
+### Content-type property
+This extension defines a new optional property for the template object: content-type. The two valid values for content-type are:
+
+* multipart/form-data (this is the one to use for uploading attachments)
+* application/vnd.collection+json (this is the one to use for sending regular CJ documents) If the content-type property is missing, clients SHOULD use application/vnd.collection+json when sending a CJ document. If the content-type property is not supported and/or the provided value is not understood by the client, the client MUST use application/vnd.collection+json when sending CJ documents.
+
+### Attachment property
+This extension defines a new property for the data object: attachment. This property is only valid for data objects that are children of the template object.
+
+The two valid values for the attachment property:
+
+* true (treat this data element as an attachment to be uploaded)
+* false (treat this data element as a text element) If the client does not support the attachment property and/or the value of this property is not understood, the client MUST treat the data element as a text element.
+

actually, it should read:

"if the attachment property is missing or set to a value to client does
not understand, the client SHOULD treat the data element as a text element."

this is to cover future cases where there may be other values for
attachment or there are changes to the contentType property.


Reply to this email directly or view it on GitHub
https://github.com/collection-json/extensions/pull/7/files#r18935874.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, that's one case. or somehow in the future attachment:null means something to some other extension, for example.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

content looks good to me. there are some typo/spelling nits:

  • This extension outlines an extension...
  • This extension compiles with RFC2388...
  • Receving attachments

there may be others.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I'll fix that.

I added these guidelines, which the RFC alone doesn't cover.

Some key points to remember in the context of Collection+JSON:

  • For each data object in the write template there SHOULD be:
    • A separate part for the data object.
    • A content-disposition header of type form-data with a name parameter
      matching the template object name.
    • If the template data object has "attachment":"true" then the
      content-disposition header MAY contain a filename parameter.
    • If the template data object has "attachment":"true" then the body
      SHOULD contain the file contents.
    • If the template data object does not have "attachment":"true" then
      body SHOULD contain a value.

On Wed, Oct 15, 2014 at 10:02 PM, Mike Amundsen [email protected]
wrote:

In attachment.md:

+A client MAY receive a CollectionJson document containing a Write template which accepts attachments which the client can use to send files.
+
+### Content-type property
+This extension defines a new optional property for the template object: content-type. The two valid values for content-type are:
+
+* multipart/form-data (this is the one to use for uploading attachments)
+* application/vnd.collection+json (this is the one to use for sending regular CJ documents) If the content-type property is missing, clients SHOULD use application/vnd.collection+json when sending a CJ document. If the content-type property is not supported and/or the provided value is not understood by the client, the client MUST use application/vnd.collection+json when sending CJ documents.
+
+### Attachment property
+This extension defines a new property for the data object: attachment. This property is only valid for data objects that are children of the template object.
+
+The two valid values for the attachment property:
+
+* true (treat this data element as an attachment to be uploaded)
+* false (treat this data element as a text element) If the client does not support the attachment property and/or the value of this property is not understood, the client MUST treat the data element as a text element.
+

content looks good to me. there are some typo/spelling nits: - This
extension outlines an extension... - This extension compiles with
RFC2388... - Receving attachments there may be others.


Reply to this email directly or view it on GitHub
https://github.com/collection-json/extensions/pull/7/files#r18938402.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK just copied into Word and did a big spell/grammar check and fixed all
issues that came up. I made some slight changes to this wording (this is
the final)

  • application/vnd.collection+json - This is the one to use for sending
    regular CJ items. If the content-type property is missing, not supported
    and/or the client does not understand the provided value, the client MUST
    use application/vnd.collection+json when sending CJ documents.

Also I now use Collection+JSON once at the beginning and then CJ everywhere
else.

On Wed, Oct 15, 2014 at 10:02 PM, Mike Amundsen [email protected]
wrote:

In attachment.md:

+A client MAY receive a CollectionJson document containing a Write template which accepts attachments which the client can use to send files.
+
+### Content-type property
+This extension defines a new optional property for the template object: content-type. The two valid values for content-type are:
+
+* multipart/form-data (this is the one to use for uploading attachments)
+* application/vnd.collection+json (this is the one to use for sending regular CJ documents) If the content-type property is missing, clients SHOULD use application/vnd.collection+json when sending a CJ document. If the content-type property is not supported and/or the provided value is not understood by the client, the client MUST use application/vnd.collection+json when sending CJ documents.
+
+### Attachment property
+This extension defines a new property for the data object: attachment. This property is only valid for data objects that are children of the template object.
+
+The two valid values for the attachment property:
+
+* true (treat this data element as an attachment to be uploaded)
+* false (treat this data element as a text element) If the client does not support the attachment property and/or the value of this property is not understood, the client MUST treat the data element as a text element.
+

content looks good to me. there are some typo/spelling nits: - This
extension outlines an extension... - This extension compiles with
RFC2388... - Receving attachments there may be others.


Reply to this email directly or view it on GitHub
https://github.com/collection-json/extensions/pull/7/files#r18938402.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for the Write Template section[0]

  • ​replace instances of content-type with contentType
  • replace "compile" with "complies"
  • normalize the use of "NOTE:....." in the Attachment Property section vs.
    inline text in the ContentType section. I like the NOTE format, but it's up
    to you.

If you want to talk about body parts, I think you need to identify them in
the Example.

for the Multipart Requests section[1]

  • normalize references to data object, template object, & template data
    object.
  • change attachements to attachments

[0]
https://github.com/glennblock/extensions/blob/master/attachment.md#write-template
[1]
https://github.com/glennblock/extensions/blob/master/attachment.md#mulipart-requests

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I've made the edits (I think). I've added a specific reference to
parts from the draft doc [1] which defines what a part is.

[1] -
https://tools.ietf.org/html/draft-ietf-appsawg-multipart-form-data-05#section-5

On Wed, Oct 15, 2014 at 11:40 PM, Mike Amundsen [email protected]
wrote:

In attachment.md:

+A client MAY receive a CollectionJson document containing a Write template which accepts attachments which the client can use to send files.
+
+### Content-type property
+This extension defines a new optional property for the template object: content-type. The two valid values for content-type are:
+
+* multipart/form-data (this is the one to use for uploading attachments)
+* application/vnd.collection+json (this is the one to use for sending regular CJ documents) If the content-type property is missing, clients SHOULD use application/vnd.collection+json when sending a CJ document. If the content-type property is not supported and/or the provided value is not understood by the client, the client MUST use application/vnd.collection+json when sending CJ documents.
+
+### Attachment property
+This extension defines a new property for the data object: attachment. This property is only valid for data objects that are children of the template object.
+
+The two valid values for the attachment property:
+
+* true (treat this data element as an attachment to be uploaded)
+* false (treat this data element as a text element) If the client does not support the attachment property and/or the value of this property is not understood, the client MUST treat the data element as a text element.
+

for the Write Template section[0] - ​replace instances of content-type
with contentType - replace "compile" with "complies" - normalize the use of
"NOTE:....." in the Attachment Property section vs. inline text in the
ContentType section. I like the NOTE format, but it's up to you. If you
want to talk about body parts, I think you need to identify them in the
Example. for the Multipart Requests section[1] - normalize references to
data object, template object, & template data object. - change attachements
to attachments [0]
https://github.com/glennblock/extensions/blob/master/attachment.md#write-template
[1]
https://github.com/glennblock/extensions/blob/master/attachment.md#mulipart-requests


Reply to this email directly or view it on GitHub
https://github.com/collection-json/extensions/pull/7/files#r18940127.

### Example
```javascript
{
"template" : {
"data" : [
{"name" : "full-name", "value" : ""},
{"name" : "email", "value" : ""},
{"name" : "avatar", "attachment": "image/jpeg"}
]
}
}
```
## Sending attachments
A client may send a request that contains attachments using the media type "multipart/form-data". It contains the data for the write template as well as attachments.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@glennblock : maybe we should add content-type or enc-type (from HTML.FORM) to the template properties instead of having the client scan the list of items to find an "attachment" property on one (or more) of the data elements.

not sure of this as it opens up the possibility of other enc-types (which might be a good idea, but is out-of-scope for your extension).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, but a template could contain multiple attachments, each one tied to a specific data element. Also things like "prompt" etc are completely relevant.


### Parts
* All _attachment_ fields in the data element must have a corresponding part.
* The part must have a name matching the form element name.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't understand any of this "Parts" section. what is a Part? where is it in the example?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A multipart request consists of mulitple parts. The document is a part and the attachment is a part.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the wording of "Body Part" to make it more explicit. Both "part" and "body part" are used in the RFC.

### Example
Below you can can see the request contains a write template with contact information. The template contains an avatar _attachment_ item with the value of the attachment being 'jdoe'. There is an additional part which contains the avatar image which has a _name_ of 'jdoe'
```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think the text refers to the template example above as well as the HTTP payload below, right? please move text around as needed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

content-type: multipart/form-data, boundary=AaB03x

--AaB03x
content-disposition: form-data; name="full-name"
content-type: text/plain; charset=us-ascii
John Doe
--AaB03x
content-disposition: form-data; name="email"
content-type: text/plain; charset=us-ascii
[email protected]
--AaB03x
content-disposition: form-data; name="avatar"
content-type: image/jpeg
...
--AaB03x
```
## Receving attachments
A client may also receive a response that contains attachments. In these cases the response media type will be "multipart/mixed" containing parts for a collection+json document as well as attachments.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@glennblock: responding w/ multipart/mixed is likely to break existing Cj clients that know nothing about this extension.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, so how about this?

  • If the client sends an accept of "multipart/mixed" they get the multipart response.
  • Otherwise the client gets a collection+json response. Looking through the response they will be able to tell that there are attachments by identifying the "attachment" fields.

For the non multipart response, another option is to have a link or something at the doc level that indicates it has attachments.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think something odd is going on here. why return a collection as
mixedpart at all? what problem is this solving that isn't covered by link
elements w/ a render value?

On Sun, Oct 12, 2014 at 2:04 PM, Glenn Block [email protected]
wrote:

In attachment.md:

+--AaB03x
+content-disposition: form-data; name="full-name"
+content-type: text/plain; charset=us-ascii
+John Doe
+--AaB03x
+content-disposition: form-data; name="email"
+content-type: text/plain; charset=us-ascii
[email protected]
+--AaB03x
+content-disposition: form-data; name="avatar"
+content-type: image/jpeg
+...
+--AaB03x
+```
+## Receving attachments
+A client may also receive a response that contains attachments. In these cases the response media type will be "multipart/mixed" containing parts for a collection+json document as well as attachments.

OK, so how about this?

  • If the client sends an accept of "multipart/mixed" they get the
    multipart response.
  • Otherwise the client gets a collection+json response. Looking
    through the response they will be able to tell that there are attachments
    by identifying the "attachment" fields.

For the non multipart response, another option is to have a link or
something at the doc level that indicates it has attachments.


Reply to this email directly or view it on GitHub
https://github.com/collection-json/extensions/pull/7/files#r18748954.


### Parts
* The first part in the document will be a CollectionJson document. The document will contain pointers back to the attachments in the response.
* All _attachment_ fields in the data element must have a value set to the name in the content-disposition header of the corresponding part.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens when two items have a filename w/ the same name value (but different images) e.g. each user uploads a file named "myavatar.png" into their own private folders.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good question. One way to handle this would be to add "Name" as a property of the disposition header. This way the name can be unique, but the filenames are the same. I originally had this but removed it as it seemed redundant. Open to ideas here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how is this handled in HTML and the RFC's you mention. surely this is
covered.

On Sun, Oct 12, 2014 at 2:10 PM, Glenn Block [email protected]
wrote:

In attachment.md:

+--AaB03x
+content-disposition: form-data; name="email"
+content-type: text/plain; charset=us-ascii
[email protected]
+--AaB03x
+content-disposition: form-data; name="avatar"
+content-type: image/jpeg
+...
+--AaB03x
+```
+## Receving attachments
+A client may also receive a response that contains attachments. In these cases the response media type will be "multipart/mixed" containing parts for a collection+json document as well as attachments.
+
+### Parts
+* The first part in the document will be a CollectionJson document. The document will contain pointers back to the attachments in the response.
+* All attachment fields in the data element must have a value set to the name in the content-disposition header of the corresponding part.

This is a good question. One way to handle this would be to add "Name" as
a property of the disposition header. This way the name can be unique, but
the filenames are the same. I originally had this but removed it as it
seemed redundant. Open to ideas here.


Reply to this email directly or view it on GitHub
https://github.com/collection-json/extensions/pull/7/files#r18748977.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't see anything, however if we drop multipart/mixed then the issue goes away.

* The document part must have a "name" of "document" as it's content-disposition header
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't see this in the example below. am i missing something?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is deprecated. I'll remove it. It is no longer necessary. The only thing necessary is making sure the first part is a document.

* All additional parts will be attachments which relate to the document.
* Each attachment must have a "name" as part of the content-disposition header.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@glennblock: i don't see this in the example below, either.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be filename. I will fix.


### Attachment Data field
The _attachment_ field in the response indicates that this item has an associated attachment. The _value_ of the attachment matches the filename in the content-disposition header in one of the parts.

### Example
Below is an example of a response containing attachments. The first part is a document which contains the list of contacts where each contact has an avatar with an _attachment_ field. Then there are additional parts which are the actual attachments. Each attachment's filename corresponds to the value of the _attachment_ field for the item in the CollectionJson document.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@glennblock When does the client make an "attachment response" request? how does it know to change the accept header to "multipart/mixed"? or even know that a multipart/mixed is coming?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we go with my suggestion that I just made, the client would know if they get a standard CJ response that has "attachment" fields.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a fan of having to "look inside" in order to sort out content-type
details. wonder if there is something we're missing. HTML doesn't have this
response issue, right?

in fact, why are we offering up a Cj collection as a multipart at all?

seems what most client would expect would be a Cj collection response with
items and maybe one of the data's link element is marked as an attachment
(render="attachment") which means you can download this element (instead of
rendering it as a "link" item or an inline image). clients that don't
understand the [render="attachment" ] directive can render the link as a
simple render="link"

On Sun, Oct 12, 2014 at 2:12 PM, Glenn Block [email protected]
wrote:

In attachment.md:

+```
+## Receving attachments
+A client may also receive a response that contains attachments. In these cases the response media type will be "multipart/mixed" containing parts for a collection+json document as well as attachments.
+
+### Parts
+* The first part in the document will be a CollectionJson document. The document will contain pointers back to the attachments in the response.
+* All attachment fields in the data element must have a value set to the name in the content-disposition header of the corresponding part.
+* The document part must have a "name" of "document" as it's content-disposition header
+* All additional parts will be attachments which relate to the document.
+* Each attachment must have a "name" as part of the content-disposition header.
+
+### Attachment Data field
+The attachment field in the response indicates that this item has an associated attachment. The value of the attachment matches the filename in the content-disposition header in one of the parts.
+
+### Example
+Below is an example of a response containing attachments. The first part is a document which contains the list of contacts where each contact has an avatar with an attachment field. Then there are additional parts which are the actual attachments. Each attachment's filename corresponds to the value of the attachment field for the item in the CollectionJson document.

If we go with my suggestion that I just made, the client would know if
they get a standard CJ response that has "attachment" fields.


Reply to this email directly or view it on GitHub
https://github.com/collection-json/extensions/pull/7/files#r18748997.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well I as offering up multipart to allow returning attachments using the standard attachment mechanism of HTTP. However I see your point. Having a link with a render="attachment" may work fine.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another idea would be using rel="enclosure" from atom.

"The value "enclosure" signifies that the IRI in the value of the
href attribute identifies a related resource that is potentially
large in size and might require special handling. For atom:link
elements with rel="enclosure", the length attribute SHOULD be
provided."

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe "download" is the right word for render="" in the responses.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@glennblock : this text needs to be updated to match the changes in the representation (e.g. link attachments).


```
content-type: multipart/mixed, boundary=AaB03x

--AaB03x
content-type: application/vnd.collection+json
{ "collection" :
{
"version" : "1.0",
"href" : "http://example.org/friends/",

"items" : [
{
"href" : "http://example.org/friends/jdoe",
"data" : [
{"name" : "full-name", "value" : "John Doe", "prompt" : "Full Name"},
{"name" : "email", "value" : "[email protected]", "prompt" : "Email"}
{"name" : "avatar", "attachment" : "jdoe.jpg"}
]
},
{
"href" : "http://example.org/friends/mamund",
"data" : [
{"name" : "full-name", "value" : "Mike Amundsen", "prompt" : "Full Name"},
{"name" : "email", "value" : "[email protected]", "prompt" : "Email"}
{"name" : "avatar", "attachment" : "mamund.jpg"}
]
}
}
}
}
--AaB03x
content-disposition: attachment; filename="jdoe.jpeg"
content-type: image/jpeg
content-transfer-encoding: binary
...
--AaB03x
content-disposition: attachment; filename="mamund.jpeg"
content-type: image/jpeg
content-transfer-Encoding: binary
...
--AaB03x
```

To see a gist with real server response with attachments go [here] (https://gist.github.com/glennblock/8db0d1facb69af67af16). You can also hit a live version [here] (http://cj-attachment.azurewebsites.net/friend) with a tool like Fiddler or using curl: `curl http://cj-attachment.azurewebsites.net/friend -v`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'd add this to the content near the top that points to the cj thread and RFCs. a kind of "cut to the chase and look at the running code first" kind of thing. just a nit ;)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK done.