1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Permission denied for attachment data

Discussion in 'XenForo Development Discussions' started by rhodes, Jun 3, 2016.

  1. rhodes

    rhodes Active Member

    I use RM and would like to read attachment data with an AJAX script

    My attachment data is here for example:
    /internal_data/attachments/0/252-b798673db57fd915cd46d6c44c63d6ad.data

    When I try to fetch this file with Ajax GET I receive an error message: 403 forbidden. I had a look at the file permissions: 644, so everybody should be able to read the file. What is my mistake? Do I have to use a kind of XF AJAX wrapper class?
     
  2. Mike

    Mike XenForo Developer Staff Member

    You can't access attachment files directly via a browser. They need to be accessed through a PHP script on the server.
     
  3. rhodes

    rhodes Active Member

    Ah ok, thank you @Mike . Is there already a XF function (url) I could call via AJAX to get the file or do I have to write my own php wrapper?
     
  4. Mike

    Mike XenForo Developer Staff Member

    The URL would be the attachments route that you see when viewing an attachment to a post, for example.
     
  5. rhodes

    rhodes Active Member

    I’ve tried to use the download URL within my AJAX call to fetch a file from the internal_data folder, but it also fails

    Example for a single RM item with attached epub:

    attachment data is here:
    /internal_data/attachments/0/252-b798673db57fd915cd46d6c44c63d6ad.data
    download link for attachment item 252:
    /attachments/my_ebook-epub.252/

    What I should do now for my customer is to provide an URL to fetch epub data with an AJAX call for further processing. Sth. like this.
    Code:
    $.get( "/attachments/my_ebook-epub.252/", function( data ) {
      //We do not get any data here. The error is permission denied;
    });
    The code above fails, so I'm looking for an alternative solution. My first thought was to create a mini module only providing an additional route (/attachmentsepub/anyfile) passing data to the GET function. But hopefully there is a better and simplier solution. Thank you for any idea.
     
  6. The Forum Heroes

    The Forum Heroes Well-Known Member

    We have had this happen to a few clients but with BD Cache and Audentio styles since 1.5.7 was released.. We resolved it by running chmod -R 0777 data internal_data again in SSH
     
  7. Mike

    Mike XenForo Developer Staff Member

    Confirm that accessing that URL directly in the works as you expect. If it does, the Ajax request should probably work. If it's not working, you may need to step through the PHP a bit to try and figure out where it's having problems.
     

Share This Page