Download and save a file from a file attachment field in QuickBase.
 Use the filename parameter to override the file name from QuickBase.
552482
def downloadAndSaveFile( dbid, rid, fid, filename = nil, vid = "0"  )
      response, fileContents = downLoadFile( dbid, rid, fid, vid )
      if fileContents and fileContents.length > 0
         if filename and filename.length > 0
            Misc.save_file( filename, fileContents )
         else
            record = getRecord( rid, dbid, [fid] )
            if record and record[fid] and record[fid].length > 0
               Misc.save_file( record[fid], fileContents )
            else
               Misc.save_file( "#{dbid}_#{rid}_#{fid}", fileContents )
            end
         end
      end
   end
222435
def attachment_upload(instance, filename):
    """"""
    return 'attachments/{app}_{model}/{pk}/{filename}'.format(
        app=instance.content_object._meta.app_label,
        model=instance.content_object._meta.object_name.lower(),
        pk=instance.content_object.pk,
        filename=filename,
    )
686772
def generate_filename(self, instance, filename):
        
        from unidecode import unidecode

        return super().generate_filename(instance, unidecode(force_text(filename)))
1213357
def save_file_as(self, file_url, new_file_name, destination_folder=None):
        
        if not destination_folder:
            destination_folder = constants.Files.DOWNLOADS_FOLDER
        page_utils._download_file_to(
            file_url, destination_folder, new_file_name)
640808
def save(self, wfs, filename=None):
        ''''''
        if self.basename and not filename:
            ext = extension(filename or wfs.filename)
            filename = '.'.join([self.basename(self._instance), ext])
        prefix = self.upload_to(self._instance) if callable(self.upload_to) else self.upload_to
        self.filename = self.fs.save(wfs, filename, prefix=prefix)
        return self.filename
1032457
def save(self, name, file):
        
        # Get the proper name for the file, as it will actually be saved.
        if name is None:
            name = file.name

        if not hasattr(file, 'chunks'):
            file = File(file, name=name)

        name = self.get_available_name(name)
        name = self._save(name, file)

        # Store filenames with forward slashes, even on Windows
        return name.replace('\\', '/')
1310876
def attach(self, id, filename, url):
        
        Attachment = self.client.model('ir.attachment')
        return Attachment.add_attachment_from_url(
            filename, url, '%s,%s' % (self.model_name, id)
        )
237941
protected function saveToDatabase(File $file, AttachableObjectInterface $object, $fieldName, FileKey $fileKey, $customFilename = null)
    {
        $attachment = $this->getOrCreateAttachment($file, $object, $fieldName, $fileKey);
        $link = $this->createAttachmentLink($file, $object, $fieldName, $attachment, $customFilename);
        
        if (in_array($fieldName, $object->getAttachableFieldNames()))
        {
            $method = 'set'.$fieldName.'Attachment';
        
            if (!method_exists($object, $method))
            {
                throw new InvalidAttachableFieldNameException('Fieldname setter for '.$fieldName.' does not exist in '.get_class($object));
            }
            
            $object->$method($attachment);
            $link->setIsCurrent(true);
            
            AttachmentLinkQuery::create()
                ->filterByAttachableObject($object)
                ->filterByModelField($fieldName)
                ->doUpdate(array('IsCurrent' => false), \Propel::getConnection())
            ;
        }
        
        $link->save();
        
        return $attachment;
    }
229576
def pickAttachment(self):
        
        filename = QFileDialog.getOpenFileName(self.window(),
                                               'Select Attachment',
                                               '',
                                               'All Files (*.*)')
        
        if type(filename) == tuple:
            filename = nativestring(filename[0])
        
        filename = nativestring(filename)
        if filename:
            self.addAttachment(os.path.basename(filename), filename)
994002
def loadFile(self, fileName):
        
        self.fileName = fileName
        self.qteWeb.load(QtCore.QUrl(fileName))
24443
def get_filename(self):
        '''  '''
        if self.filename is None or not os.path.exists(self.filename):
            tf = tempfile.mktemp() + self._default_file_extension
            self.save(tf)
            yield tf
            os.remove(tf)
        else:
            yield self.filename
318166
def save_file(self, filename, text):
        """"""
        if not filename.endswith('.py'):
            filename += '.py'
        path = os.path.join(self.currentpath, filename)
        with open(path, 'w', encoding="utf-8") as file_:
            file_.write(text)
925538
function(filename){
      if (!filename){
        filename = 'chart';
      }
      this.toImg(function(img){
        var a = document.createElement("a");
        // Name of the file being downloaded.
        a.download = filename + ".png";
        a.href = img.getAttribute('src');
        // Support for Firefox which requires inserting in dom.
        a.style.display = 'none';
        document.body.appendChild(a);
        a.click();
        document.body.removeChild(a);
      });
    }
30015
def download(url, filename, redownload):
    
    data_folder, filename = filename.rsplit('/', 1)
    download_list = [DownloadRequest(url=url, data_folder=data_folder, filename=filename, save_response=True,
                                     return_data=False)]
    download_data(download_list, redownload=redownload)
405266
def rename_file(self, instance, field_name):
        
        file = getattr(instance, field_name)

        if file:
            new_name = get_hashed_filename(file.name, file)
            if new_name != file.name:
                print('    Renaming "%s" to "%s"' % (file.name, new_name))
                file.save(os.path.basename(new_name), file, save=False)
                return True

        return False
977219
def save(self, name):
        
        with open(name, 'wb+') as f:
            while True:
                buf = self._fileobj.read()
                if not buf:
                    break
                f.write(buf)
404461
def download(self, request, **kwargs):
        '''
        
        '''
        # method check to avoid bad requests
        self.method_check(request, allowed=['get'])
        # Must be done otherwise endpoint will be wide open
        self.is_authenticated(request)

        response = None
        file_item_name = kwargs.get('name', None)
        if file_item_name:
            filename_absolute = helpers.get_filename_absolute(file_item_name)
            if os.path.isfile(filename_absolute):
                response = serve(request, os.path.basename(filename_absolute), os.path.dirname(filename_absolute))
                response['Content-Disposition'] = 'attachment; filename="{}"'.format(
                    os.path.basename(filename_absolute))

        if not response:
            response = self.create_response(request, {'status': 'filename not specified'})

        return response