For every filenode, when I click on the download link, the file that I am prompted to download is named "file". Is there any way to base this download name on the nodes title or something else?

Comments

rmh3093’s picture

this seems to only be the case if I create the file node with php using a pre existing bitcache, when I create a filenode manually the download name makes sense, am i missing a filed when creating this node

rmh3093’s picture

it seems like when i use the xmlrpc service to upload the bitstream, the mimetype gets set to application/octet-stream when it should be application/x-lzma... idk why this is getting screwed up

rmh3093’s picture

this seems to be fixed now... maybe it was cause i enabled server side mime detection

rmh3093’s picture

now some of the links end in .bin and others are correct, wtf is going on here

miglius’s picture

Most probably the problem is that the MIME type is not detected properly. Fileframework allows trusting the MIME type provided by the browser (some browsers does not post the uploaded file's MIME), detection the MIME on the server side (using fileinfo), which is not ideal as also does not work for all cases, or conditional - try to detect on the server side if the browser does not send the MIME.

rmh3093’s picture

well none of my files nodes that I create programatically display the correct mime type which should be "LZMA Archive". if I upload the file though the browser the mime type is correct, is there a way I can force the mime type or am i doing something wrong with xmlrpc which is causing the information to get lost

miglius’s picture

When you saved the file in bitcache and are creating a node, the fileframwork trust the MIME type which is pulled from the bitcache:

$file->type = isset($file->type) ? $file->type : bitcache_get(file_get_hash($file->uri))->type;

This is a bitcache function which tries to detect a MIME type:

  function mime_type() {
    if (extension_loaded('fileinfo') && ($finfo = finfo_open(FILEINFO_MIME))) {
      $type = finfo_file($finfo, $this->path);
      finfo_close($finfo);
      return $type;
    }
    else if (function_exists('mime_content_type')) {
      return mime_content_type($this->path);
    }
    else if (file_exists($this->path)) {
      // Attempts to detect a file's MIME type using the Unix `file' utility.
      // MIME content type format defined in http://www.ietf.org/rfc/rfc1521.txt
      $output = exec('file -bi '. escapeshellarg($this->path), $ignore, $status);
      if ($status == 0 && preg_match('!([\w-]+/[\w\d_+-]+)!', $output, $matches))
        return $matches[1];
    }

    return 'application/octet-stream'; // default to binary
  }

try running "file -bi your_file" on the command line to see if this utility can detect LZMA type.

rmh3093’s picture

well this would explain things, file -bi something.lzma returns application/octet-stream I had to write a patch to the file program which provided a magic code for lzma archives ;) thanks for your help... my server is down atm so I cant confirm that my new binary will help but I think it will

I will report back asap

miglius’s picture

Status: Active » Postponed (maintainer needs more info)
johanneshahn’s picture

Status: Postponed (maintainer needs more info) » Closed (fixed)

feel free to reopen issue