ari_linn: (warrior - normal)
Ари Линн ([personal profile] ari_linn) wrote in [site community profile] dw_dev2018-04-13 07:27 pm
Entry tags:

Is there any way I can programmatically authorize to upload multiple files to Dreamwidth by a script

I have about 100 files that I want to upload to Dreamwidth. I want to do it with a script, if it's possible. I checked what happens in my browser when I'm logged in and uploading a file at https://www.dreamwidth.org/file/new , and it was pretty much the following request:

POST https://www.dreamwidth.org/api/v1/file/new 
Content-Type: multipart/form-data
Cookies: ljuniq=THISTOKENCHANGESWITHEVERYREQUEST;
BMLschemepref=celerity-local;
__utma=SOMETOKEN;ljmastersession=YETANOTHERTOKEN;
ljloggedin=FINALTOKEN

FILE BODY
My problem now is: how do I get the whole cookies/authorization stuff, or at least THISTOKENCHANGESWITHEVERYREQUEST token (other stuff seems to be reused? can I hijack my current session and simply use cookies from it in my script?) Is there any way to do it programmatically?
momijizukamori: Green icon with white text - 'I do believe in phosphorylation! I do!' with a string of DNA basepairs on the bottom (Default)

[personal profile] momijizukamori 2018-04-14 01:59 pm (UTC)(link)

Glad it worked! Yeah, I think that maybe needs to be better documented somewhere - I think I found it by just seeing if it worked (because it's a UX pattern that's becoming pretty common). Glad I could save you some work!