Skip to content

got error when fs.wirteFile #328

Closed
Closed

Description

@teamrun

i setup a dropable element and read base64 string from it and fs.writeFile, then i got this Error:

Error {errno: -13, code: "EACCES", path: "/photo.jpg"} 

Here is the code:

reader.onloadend = ->
    previewImg.attr('src', reader.result)
    fs.writeFile '/photo.jpg', reader.result, (err) ->
      console.log(err)

it works well if it set filepath '/tmp/photo.jpg', the picture is writed into /tmp folder of my hddrive, so it is not allowed to writeFile to current path?

Activity

  1. tnako commented on May 18, 2014

    @tnako

    For current path you need to write './photo.jpg' (add dot before slash).

  2. teamrun commented on May 19, 2014

    @teamrun
    Author

    i tryed this, got same error. it seems like it is not allowed to write file to current path, the app's path.

    /tmp/photo.jpg and /Users/userName/Documents/dev/photo.jpg works

  3. zcbenz commented on May 20, 2014

    @zcbenz
    Contributor

    File paths passed to Node's APIs are treated as real file system paths, instead of the relative paths used by HTML. So /photo.jpg in your case represents the photo.jpg under the /, e.g. the file system's root.

  4. teamrun commented on May 21, 2014

    @teamrun
    Author

    yeah, it my fault. I required path module and path.join to get the right write path and it works well. Thank you all

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions