eddelbuettel / rpushbullet

R interface to the awesome Pushbullet service
https://eddelbuettel.github.io/rpushbullet
94 stars 19 forks source link

Error: "The param 'file_url' has an invalid value." when pushing image #70

Open eldenvo opened 1 year ago

eldenvo commented 1 year ago

When trying to push an image, I get the following error:

Warning message: 400{"error":{"code":"invalid_param","type":"invalid_request","message":"The param 'file_url' has an invalid value.","param":"file_url","cat":"\u003e:3"},"error_code":"invalid_param"}

Reproducible code below.

`p <- ggplot(mtcars, aes(x = cyl, y = mpg)) + geom_point()

file <- tempfile("test", fileext = ".png")

ggsave(file, p)

pbPost(type = "file", title = "test", url = file, filetype = "image/png") `

Using R 4.2.2 on Windows 11

eddelbuettel commented 1 year ago

Thanks for report. Uploading files is a little tricky, see the docs. Can you try with the debug= and verbose= flags? We may need to dig into the code to see if the initial upload of the file worked.

eldenvo commented 1 year ago

Thanks - sorry for bringing up an issue on a package that's been quiet for a while but its a very handy package!

With debug and verbose:

> pbPost(type = "file",
+        title = "test",
+        url = file,
+        filetype = "image/png", debug = T, verbose = T)
missing recipient and email and channel
dest is:  1 
in lapply, d is: 1
$device_iden
[1] "ujzoMaldoc0sjxvvrT49Ey"

$type
[1] "file"

$file_name
[1] "test60086d267e5.png"

$file_type
[1] "image/png"

$file_url
[1] "https://dl3.pushbulletusercontent.com/2HSYeaKeXuQ9dL6du6BdRznZ3rHz8Qmy/C:%5CUsers%5Calexd%5CAppData%5CLocal%5CTemp%5CRtmpmmPAaA%5Ctest60086d267e5.png"

$body
[1] ""

Warning message:
400{"error":{"code":"invalid_param","type":"invalid_request","message":"The param 'file_url' has an invalid value.","param":"file_url","cat":"\u003e:3"},"error_code":"invalid_param"} 

That URL does seem to point to the correct image

eddelbuettel commented 1 year ago

Thanks for the follow-up. This helps. So we have a file_url that is a valid string. Good.

But the docs are confusing. I see nothing changed. Though https://docs.pushbullet.com/#upload now also mentions 'upload_url' as well as 'file_url'. It is a bit of a hail mary -- maybe sending it a upload_url value would work?

On the other hand, ~https://docs.pushbullet.com/#create-push~ https://docs.pushbullet.com/#push-a-file still refers to file_url and shows a URL starting wuth dl as we have. Hm.

eldenvo commented 1 year ago

Not sure that upload_url helped.

As shown, when creating the upload request, I get a file_url that is a valid string

$file_url
[1] "https://dl3.pushbulletusercontent.com/4367JJaVh5oDaOXokp7ovqG4G5lLRMC9/C:%5CUsers%5Calexd%5CAppData%5CLocal%5CTemp%5CRtmpmmPAaA%5Ctest600817d73365.png"

However, trying to look into the .createPush function, and using the same inputs, it is coming our with this:

rawToChar(res$content)
[1] "{\"data\":{\"acl\":\"public-read\",\"awsaccesskeyid\":\"AKIAJJIUQPUDGPM4GD3W\",\"content-type\":\"image/png\",\"key\":\"6s2tRpknyQJNe8Ys9nKwgm23pcffN6qf/test600817d73365.png\",\"policy\":\"eyKjb25kaXRpb25zIjTE6MzcuMjM0MTMwWiJ9\",\"signature\":\"UX5s1uIy1ov6+xlj58JY7rGFKcs=\"},\"file_name\":\"test600817d73365.png\",\"file_type\":\"image/png\",\"file_url\":\"https://dl3.pushbulletusercontent.com/6s2tRpknyQJNe8Ys9nKwgm23pcffN6qf/test600817d73365.png\",\"upload_url\":\"https://upload2.pushbullet.com/upload-legacy/sx8gzzCcRaXrjvS1FhN8QSK27eJ0x8rj\"}"

The file_url appears to be different, and doesn't lead to a valid image.

I don't fully understand curl etc myself, so not sure if this is expected or if something is going wrong in the creation of the push params?

eddelbuettel commented 1 year ago

The next debug step is indeed to do it 'by hand' following the pushbullet API tutorial. The basic command argument to curl (the command-line binary) are shown there; if we know what works we can update how R calls it. Would appreciate it if you could give that a whirl.