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

Can't writeBin without removing filename attribute when using a file parameter #582

Closed
meztez opened this issue Jul 2, 2020 · 5 comments · Fixed by #636
Closed

Can't writeBin without removing filename attribute when using a file parameter #582

meztez opened this issue Jul 2, 2020 · 5 comments · Fixed by #636
Milestone

Comments

@meztez
Copy link
Collaborator

meztez commented Jul 2, 2020

writeBin does not like the raw vector to have attributes (in this case filename)

#* @apiTitle Upload test

#* @param pdf:file
#* @post /upload
function(pdf) {
  f <- tempfile()
  on.exit(unlink(f), add = TRUE)
  writeBin(pdf, tempfile())
  class(pdf)
}

#* @param pdf:file
#* @post /upload2
function(pdf) {
  f <- tempfile()
  on.exit(unlink(f), add = TRUE)
  writeBin(as.raw(pdf), tempfile())
  class(pdf)
}

#* @param pdf:file
#* @post /upload3
function(pdf) {
  f <- tempfile()
  on.exit(unlink(f), add = TRUE)
  attr(pdf, "filename") <- NULL
  writeBin(pdf, tempfile())
  class(pdf)
}

upload : Error in writeBin(pdf, tempfile()): can only write vector objects
upload2 and upload3 : ok

Should we fix or document use case?

If fix:
a) remove attributes
b) return a named list of bytes list(filename = bytesVector); comes with testing what filename constitute a valid R name.
c) other option that comes down to where does filename should live during execution

@schloerke
Copy link
Collaborator

I like the solution of /upload2. I also like the idea of list(filename = rawVec) as it extends to multi-file upload as well. If no name is provided, then we can do list(rawVec).

(** Asking team)

@schloerke schloerke added this to the v0.5.0 - Next CRAN release milestone Jul 2, 2020
@schloerke
Copy link
Collaborator

schloerke commented Jul 2, 2020

list(filename = bytesVector) feels much cleaner. Waiting for more feedback.

@meztez
Copy link
Collaborator Author

meztez commented Jul 2, 2020

PR incoming

@schloerke
Copy link
Collaborator

Thank you @meztez . I think the list(filename = bytesVector) is the better approach.

This will make multipart forms much easier as well. (list(f1 = val1, f2 = val2))

(Great catch!)

@schloerke
Copy link
Collaborator

Fixed in #636

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants