@prologic@twtxt.net - I do not want to nag about it - but did you find some way to post image through curl? (Or could you share the almost-working solution that you tried?), if you have not had time - then that’s fine too. I want to start looking into it again :)
@stigatle@yarn.stigatle.no Yeah sorry about that! Here’s how to do it!
$ curl -F media_file=@gitea.png -H "Token: $YARND_TOKEN" https://twtxt.net/api/v1/upload
{"Type":"taskURI","Path":"https://twtxt.net/task/FiBmMQbNF7bicLSZsWybmN"}
$ curl https://twtxt.net/task/FiBmMQbNF7bicLSZsWybmN | jq '.'
{
"state": "complete",
"error": "",
"data": {
"mediaURI": "https://twtxt.net/media/rhkm36YACemg7TBmG7d2Q6.png"
}
}
“
Basically:
- Hit the
/api/v1/upload
endpoint with a valid token andmedia_file
as a Form URL encoded payload.
- Hit the Task endpoint you get back until
status=complete
- Use the URI once complete
This works for:
- images
- video
- audio
If you wouldn’t mind updating the Wiki with this info 😅
@prologic@twtxt.net Sure, I’ll do that!
Thank you so much, I’ll start working on getting it into the client tonight.
Started on it tonight, got the file pick dialog to work, so now I just need to get the json stuff to work.
@stigatle@yarn.stigatle.no Yeah saw you got it working! Nice one 👌 Very happy about that! Did you also manage to implement the polling too? (which is important for longer tasks, like uploading a video, which does some transcoding on the backend)
No polling yet, but that part is important as you say, I will need to implement that. Now I have the pieces I need at least :)
@stigatle@yarn.stigatle.no Yeah it’s basically just calling the task URI you get back as I showed in the other thread 👌
@prologic@twtxt.net I do that now, and all that works, it’s just that I do not (currently) check it multiple times, in the test I did it completed as soon as the image was uploaded. But yeah I have to do some more with that for bigger files for sure. I’ll look into that next.
Reckon we should publish your client on the landing page at some point? 🤔
@prologic@twtxt.net that would make me proud. Ill add more description and screenshots to the readme so that people can see more easily what it looks like etc. I also want to make ready packages for it, and see if I can crosscompile for windows as well.
@stigatle@yarn.stigatle.no Remind me where the project’s home page is again? 🤔
I had some time to code this afternoon, so I have made some polling now, so if a task is not completed it waits 2 secs and tries again, if the server reports a error in the task it stops polling, when the task is successfull it will add the resulting image tag to the status input field. Quite pleased with this now. After this I’ll work on ‘view conversation’, meanning you can open a conversation and see all posts in it, that’ll make it even easier to follow conversations and to reply etc.
@stigatle@yarn.stigatle.no Nice 👌
@prologic@twtxt.net Quick question, does this mean you need to put the entirety of file contents in the URL? Why not instead put it in the POST request body?
@shreyan@twtxt.net Umm, no, the file’s contents are just URL encoded. That can either by in the Query String, or Request Body, but not both. It’s a pretty standard way of encoding a form.
You can see the implemtnation here: https://git.mills.io/yarnsocial/yarn/src/commit/a14ab3c021ad4925a6f0bee38e8d2c098cdab8d6/internal/api.go#L949-L961
@prologic@twtxt.net Ah, thanks 🙂, I wasn’t sure