Question: 404 Not Found When Downloading Attached File

404 Not Found When Downloading Attached File

Hello, Everything is working fine so far. However, when I am trying to download the files (png, jpg) I have attached in the invoice, it's giving me 404 Not found error and can't download the

SK

Sarang Kim

Asked
Hello, Everything is working fine so far.
However, when I am trying to download the files (png, jpg) I have attached in the invoice, it's giving me 404 Not found error and can't download the files.

This is the link.
https://wujukorea.com/admin/welcome/download/74f159c08ac7ae322ae73a9cf8a4635d.png

Do you know what could be causing this?
  • MS

    Mian Saleem

    Answered
    Hello,

    I can't check your server. I can only check the item, if having issue. You will need to check with your server admin for any server config/issue.

    I am not saying you to delete the `location /` but the following

    ```
    location ~ /files {
    deny all;
    return 404;
    }
    ```

    I am suspecting this.
  • SK

    Sarang Kim

    Answered
    I did that and still not working.

    And also, I am running multiple websites with PHP Scripts, none of them have this problem.

    Did you even check the item?
  • MS

    Mian Saleem

    Answered
    Hello,

    **_You can check it on live demo. Your download and demo are exact same._**

    There are more than thousand people using the item and if the issue is with item code, every one should have it not only you. I am sure it's not the item code as I have tested it after your question but still try to help.

    If you have removed the file, you need to restart the nginx and test.

    Thank you
  • SK

    Sarang Kim

    Answered
    I did removed the file, and restarted the nginx and tested, still, when downloading the attachments, i am getting 404 and when even trying to delete the attached file, i am getting 'ajax call fail'
  • MS

    Mian Saleem

    Answered
    Hello,

    I am sorry if I was not clear. It's not about paid support. You are supported and we will try our best to help.

    The issue here is some nginx config and we are not good with server management. We use third-party software to manage servers. You can check ploi.io or laravel forge. I think ploi offer 1 server free account too.

    I have check the route and links, download attachment is working but I have no clue why your nginx showing 404. The ajax call issue is due to same reason. Your server admin might help to check the cause.

    Thank you
  • EG

    Enyinnaya Gift

    Answered
    Those on nginx server can add this code to their nginx config **nginx.conf**
    ```
    location /admin/welcome/download/ {
    alias /var/www/wwwroot/files/;
    add_header Content-disposition "attachment";
    }
    ```

    ***OR***

    Replace attachment function in `core.js` file via `themes\default\admin\assets\js\core.js`

    with the function below

    ```
    function attachment(x) {
    return x == null || x == 0
    ? ''
    : x == 1
    ? '<div class="text-center"><i class="fa fa-check"></i></div>'
    : '<div class="text-center"><a href="' +
    'files/' +
    x +
    '" target="_blank" class="tip" title="' +
    lang.download +
    '"><i class="fa fa-file"></i></a></div>';
    }
    ```
  • MS

    Mian Saleem

    Answered
    **[Enyinnaya Gift](/u/giftedhands4real)** Thank you for sharing. The first solution seems fine. If the access if denied to files, the second option will get the same error. Won't it?
  • EG

    Enyinnaya Gift

    Answered
    No, it won't. It will open the file in a new browser tab.

    I did test both options on a client's Nginx server having the same reported issue and it works fine.

    I kind of even prefer the second option.
  • MS

    Mian Saleem

    Answered
    **[Enyinnaya Gift](/u/giftedhands4real)** Hello,

    Does the nginx config has

    ```
    location ~ /files {
    deny all;
    return 404;
    }
    ```

    It should allow direct access, if it is blocking for php OR the issue might be different as I think :(

    Thanks for the solution
  • Login to Reply