Convenience method for attaching files to a fetched record

        :param args: args to pass along to `Attachment.upload`
        :param kwargs: kwargs to pass along to `Attachment.upload`
        :return: upload response object
349371
def upload(self, *args, **kwargs):
        

        return self._resource.attachments.upload(self['sys_id'], *args, **kwargs)
480977
def render_to_response(self, context, **response_kwargs):
        
        filename = os.path.basename(self.object.file.name)

        # Try to guess the content type of the given file
        content_type, _ = mimetypes.guess_type(self.object.file.name)
        if not content_type:
            content_type = 'text/plain'

        response = HttpResponse(self.object.file, content_type=content_type)
        response['Content-Disposition'] = 'attachment; filename={}'.format(filename)

        return response
1294658
def upload(self,
               url,
               method="POST",
               file_path=None):
        
        if not os.path.exists(file_path):
            raise RuntimeError("")

        with open_file(file_path, 'rb') as file:
            size = os.path.getsize(file_path)
            label = "Uploading {filename} ({size:.2f}MB)".format(
                filename=os.path.basename(file_path),
                size=size / float(self.chunk_size) / self.chunk_size
            )

            if method == "PUT":
                resp = put(url, data=file)
            elif method == "POST":
                resp = post(url, data=file)

            content_iter = resp.iter_content(chunk_size=self.chunk_size)

            with progressbar(content_iter,
                             length=size / self.chunk_size,
                             label=label) as bar:
                for _ in bar:
                    pass
396491
def add_download_filename(response: HttpResponse, filename: str) -> None:
    
    # https://docs.djangoproject.com/en/1.9/howto/outputting-csv/
    add_http_headers_for_attachment(response)
    response['Content-Disposition'] = 'attachment; filename="{}"'.format(
        filename)
1279108
def _upload(param_dict, timeout, data):
    
    param_dict['format'] = 'json'
    param_dict['wait'] = 'true'
    param_dict['bucket'] = 'audio_summary'
    result = util.callm('track/upload', param_dict, POST = True, socket_timeout = 300,  data = data)
    return _track_from_response(result, timeout)
1008759
def attachment_show(self, id, **kwargs):
        ""
        api_path = "/api/v2/attachments/{id}.json"
        api_path = api_path.format(id=id)
        return self.call(api_path, **kwargs)
1215815
def update_file(self, uuid, file_path, async=False):
        
        url = "documents/{u}/upload?async={a}".format(u=uuid, a=async)
        return self.core.upload(file_path, url, http_method='PUT')
400791
def action_update(self):
        

        order = []
        form = self.request.form
        attachments = form.get("attachments", [])

        for attachment in attachments:
            # attachment is a form mapping, not a dictionary -> convert
            values = dict(attachment)

            uid = values.pop("UID")
            obj = api.get_object_by_uid(uid)

            # delete the attachment if the delete flag is true
            if values.pop("delete", False):
                self.delete_attachment(obj)
                continue

            # remember the order
            order.append(uid)

            # update the attachment with the given data
            obj.update(**values)
            obj.reindexObject()

        # set the attachments order to the annotation storage
        self.set_attachments_order(order)

        # redirect back to the default view
        return self.request.response.redirect(self.context.absolute_url())
723947
def upload_create(self, data, filename=None, token=None, **kwargs):
        ""
        api_path = "/api/v2/uploads.json"
        api_query = {}
        if "query" in kwargs.keys():
            api_query.update(kwargs["query"])
            del kwargs["query"]
        if filename:
            api_query.update({
                "filename": filename,
            })
        if token:
            api_query.update({
                "token": token,
            })
        return self.call(api_path, query=api_query, method="POST", data=data, **kwargs)
970595
def upload_attachment(self, location, data):
        
        self.validate_attachment_location(location)
        content = data.read() if hasattr(data, 'read') else data
        orig_content = content
        if isinstance(content, bytes):
            content = base64.b64encode(orig_content).decode('ascii')
        else:
            pass  # Should be base64 encoded already
        apath = '%s/%s' % (self.attachment_location, location)
        url = '%s/contents/%s' % (self.base_url, apath)
        result = requests.put(
            url, auth=(self.user, self.token), data=json.dumps({
                'message': 'file attachment %s' % location,
                'content': content}))
        if result.status_code != 201:
            raise ValueError(
                "Can't upload attachment %s due to error %s." % (
                    location, result.reason))
        return '[%s](https://github.com/%s/%s/blob/master/%s)' % (
            location, self.owner, self.realm, apath)
1125121
def upload(self, file_obj):
        
        return self._client.upload_object(
            self._instance, self._bucket, self.name, file_obj)
611015
def uploads(self, option):
    
    params = join_params(self.parameters, {"uploads": option})

    return self.__class__(**params)
1105077
def attach_files(self, files: Sequence[AttachedFile]):
        '''
        
        '''
        assert not self._content, 'content must be empty to attach files.'
        self.content_type = 'multipart/form-data'
        self._attached_files = files
1014475
def fetch_attachment(name)
      raise ArgumentError, "doc must be saved" unless self.rev
      raise ArgumentError, "doc.database required to put_attachment" unless database
      database.fetch_attachment(self, name)
    end
449866
def _attacher(self, key, value, attributes, timed):
        
        id, extra = self._get_attach_id(key, value, attributes)

        record = self._create_attach_record(id, timed)

        if extra:
            record.update(extra)

        return record
488786
def upload_url(url, options = {})
      params = upload_params(options).for_url_upload(url)
      token = request_file_upload(params)

      upload_status = poll_upload_result(token)
      if upload_status['status'] == 'error'
        raise ArgumentError.new(upload_status['error'])
      end

      Uploadcare::Api::File.new(self, upload_status['file_id'])
    end
381692
def set_uploading(self, files_uploaded):
        
        self.files_uploaded = files_uploaded
        self.__record_progress(Status.UPLOADING_FILES)