nostr-protocol / nips

Nostr Implementation Possibilities
2.29k stars 558 forks source link

"attached" url field #100

Open earonesty opened 1 year ago

earonesty commented 1 year ago

a data url can allow for the embedding of images with mime type:

https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs

or the embedding of a gif, or podcast link or whatever

a single url field as an "attachment" should be more than enough for all major use cases that people have been discussing

the field can just be named url. the decision as to what to do with the url can be based on the event type (for example, a set_profile event vs a text_note event can use the url for the profile pic vs an embetted pic to go along with the note)

example of an embedded image:

data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAnWSURBVHhe1ZsJdFTVGce/92YmIcUIIlsgKAbBIjTR2sKRFlxowVoqtEXx0CrVBk5LS6VKe6qn7el6WtRaAZWm2EWPGy0q1K2L1gUKasClVKyxKpywg+xCMst7/f/fvZPMJO/NTObdYfmd8+UuM5l53/e+e+/33XfHkhJzZNGAwSjOh3wMMhTCdl9ID0gUQpKQA5BdkCYtr0HWVMzZugllyTBuAChso/gk5ErIeMgwSBjegyzXsgoGcdhpCmMGgOKnovgmZDokrNJB0Bt+C2mAId73ekIS2gBa8e9D6iEnse8okIDcDpkf1hBFGwCKc/x+G3ITpCf7jgEtkBshd8AQnEe6TFEGgPJno6ArfsLrOPashsyCEd5QzcLhhNUloDzHeSPkeFGejIGsx7XNVM3CKdgD8OExFLdCvuV1HL8shlwHb+A8kZeCDADlK1DcC5nqdRz/PAr5EoxwRDWDyWsArfxSyOe8jhOHv0CuzGeEnHOAdvv7IOaVd11dKRmXQe6DDulo05d8k+B8yBdU1SyREdMl9ulFEhl5lVinDEFP0StyLnjtjBcCCfxWWO7rKO5SLdO4EvvMEokM+axuutL6+zpxjyCmsSNi9awRd8/b6jUz1GMo/E7Xs/D1AChfh+JXqlUKLLEHMD9SuHubxD3MPAgX1LdOyqc/J+X1/5HYh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c1TdVXM/9PmD3RirrnQVQeHff7B3OxRrILaraTtC3cycz/1PLAOi+iZU/ktYHLpLWZZPalPRS5IwJr31olBzqMhM3t9PmT+CagglxFooG1TIElLfKeyBoGisWgqZU4+3itu7XL5aUuVDeN77OuajCCDwnyPOCJzL8LUFgmJ9zAOIfearqSdU6IXkYwtAxkILCKnjCMyguVq0Thicgl+MmFn9YOg0+hMnSieQJj0DyKk8KXoPwYTzYa3ZSLA3cNc17TD5NlzMLDAeeJOWXmH+cFg4+4rsBiv9GNQujywYgMALPut4N8T/8c/Rh4HYtlF+vmoVTlAHSwBCcYX8I4c9gjwWM7fmbRf6Q8uj9bC4TGIFHNX4A4dA4Wj+c5KYCQ/YFUPzY/HCyIzBEJQoGHF+FlOrQBXet7oTcE1bxNMYMkAmMwZhhMoTnD/3PyBQOlV4B4br+LBQv4MFC4ZTEAJnAGNUoLoDUQvhIh94R9PP5nRAqzKdVr0DWQeECDxsXg8j/ATnjJMJXpNMwAAAAAElFTkSuQmCC

fiatjaf commented 1 year ago

I don't know if this is a good idea (I think it is not), but, if it is, then we can probably refer to these attachments inside the note content like email attachments?

earonesty commented 1 year ago

i think there's no other good way to publish images. url's won't work because they have to be hosted. putting it in the note content is ok, rendering agents can just know about "data urls" and everything can work fine. but none of them do. maybe all that's needed is a NIP that gives hints as to how to parse and render urls when observed in notes?

the only major downside of embedding image data in the notes is that notes can swiftly become un-human-readable and extremely large. and with limits, agents will be tempted to spam nostr with 50 notes in order to render one very large video, etc. and then everyone will have their own way of breaking up images and we'll have the MMS nightmare

i feel like keeping media "out of band" is a great way to clean up the notes

be cool to be able to grab a note and not reference the media, for example

maybe a new kind of url that refers to another note is a clean way of doing this?

hey check out my image: nostr://<hex-event-id-of-event-containing-image-data>

and then i can filter out media notes easily, archive them easily, and use them to render only if i want to....

the spec can be as simple as this:

given a nostr link, follow the link, get the contents, and whatever the contents are, treat them as if they are the link

fiatjaf commented 1 year ago

Why URLs won't work?

earonesty commented 1 year ago

if i had persistent, quality centralized hosting, why would i use nostr? seems to defeat the purpose, imo. but maybe i'm missing something. i guess it's ok to just tell users that images and media have to be "hosted elsewhere", but without a simple and standard way to embed and if nostr takes off - people will just invent one.

but yeah, i can use a data url, like above... but it really clutters the note right? and leads to comingling the note with the image in one big blob. "internal refs" clean that up, keep notes small and readable

if you paste that data url in the browser it renders fine by the way (no its not rick astley)

fiatjaf commented 1 year ago

The purpose of Nostr is not to replace the internet, although I don't know how to answer your question exactly right now without writing an essay. I think my basic point is that image hosting services do not need the censorship-resistance guarantees that Nostr provides and they are much more efficient than Nostr.

What I expect to happen is that clients that want to offer a good UX will have built-in image hosting providers that users will be able to use seamlessly.

Meanwhile I also expect most relays to block large events as time goes by unless they're being well-paid for that, so the data-url hack will eventually stop working.

vitorpamplona commented 1 year ago

Just encourage IPFS (hashed ids to make sure the content doesn't change) for external data.

There is a point here that external servers can be used to pixel-track the location of users (by IP), including the profile image.

fiatjaf commented 1 year ago

IPFS can be used, yes. Ideally we would just use IPFS for files like that and it would work. In practice IPFS doesn't work, but I don't see a reason why it can't be tried.

Tracking people with images is a problem that clients must solve by themselves. They don't have the obligation to automatically load the image. Email has this problem, other platforms like message boards and instant messaging apps have this problem. Each solves it in their own way.

5hanth commented 1 year ago

A possible NIP to provide a standard method for hosting images, videos, and large files. The NIP will enable the standard of SDKs for clients to conveniently upload files and render them. The following can be a flow:

thoughts?

ghost commented 1 year ago

perhaps another kind should be picked for this, instead of rewriting relay software. Me and Cole (author of git-nostr) are currently using 7777 as event but i think this should be a standard for blobs or large files.

And for lookups, perhaps we can add some tags such as hash-digest, filename, filesize etc

Still a rough idea, but i think it'll be very good to have a kind that is not only for images or files, but can also be used to publish other binary data

I'll write some examples tomorrow morning

arthurfranca commented 1 year ago

~NIP-23 sets a precedent when adding image tag. It could also be used with references as #[tag index] inside content for inline image.~

Meanwhile I also expect most relays to block large events as time goes by unless they're being well-paid for that, so the data-url hack will eventually stop working.

It is possible to compress image up to desired size, then turn it into a data url as @earonesty wants, so staying within relay event size limits.

Why URLs won't work?

~Some images with content-type application/octet-stream on aws s3 for example have no extension (no .jpg, .gif, ...)~

vitorpamplona commented 1 year ago

The following could work:

  1. New event kind where content is the Data URL alone: data:image/png;base64,...
  2. The Text Note Event that wants to use/display that Image in the middle of the text simply cites it in a tag: [0] -> ["e", "hexcode", "relay.."].
  3. Clients that see the tag in the content can request the image by event ID and display it in the best way they can.

It would be very similar to what we do with Quoted Posts right now.

Clients could then offer direct Image Upload into relays.

Images (and other files) could then be directly liked, zapped, reported, searched, etc.

And the idea of an external nostr:note1 -> image could also work.

We could have relays that only serve this type of larger event (probably through heavy caching mechanisms).

Then a real decentralized TikTok competitor could really emerge.

The only issue is that representing binary content as base64 inside a JSON file is quite a waste of space.