Returns a file upload field with a more pleasant interface than browser
 file inputs. Changes messaging if the `method` already exists.
 Options are forwarded to the hidden `file_field`.
483891
def attachment_field(method, options = {})
      render(partial:"admin/shared/forms/attachment_field", locals: {
        f: self,
        method: method,
        options: options,
      })
    end
1009131
public function gate() {
    
    // The upload handler class name can be set as a GET parameter, but it must exist in the config file
    if (true === isset($_GET['upload_handler'])) {
      $handler = (string) str_replace('::', '\\', $_GET['upload_handler']);
      
      $class_name = \Config::get('plupload::plupload.upload_handler_'.$handler);
    }
    else {
      $class_name = \Config::get('plupload::plupload.upload_handler');
    }

    $this->upload_handler = new $class_name;

    // The upload handler must implement a specific interface
    if (false === $this->upload_handler instanceof \Fojuth\Plupload\UploadHandlerInterface) {
      throw new \LogicException('The upload handler must implement the \Fojuth\Plupload\UploadHandlerInterface interface.');
    }
    
    // All looks fine, we start the upload
    return $this->upload_handler->upload(\Input::file('file'));
  }
1156410
def formfield(self, **kwargs):
        

        defaults = {
            'form_class': forms.CharField,
            'required': False
        }

        defaults.update(kwargs)

        form_field = super().formfield(**defaults)
        form_field.widget = forms.HiddenInput()

        return form_field
492755
public static void processInputFileField(MultipartBody request, String fieldName, InputFile inputFile) {
        String fileId = inputFile.getFileID();
        if (fileId != null) {
            request.field(fieldName, fileId, false);
        } else if (inputFile.getInputStream() != null) {
            request.field(fieldName, new InputStreamBody(inputFile.getInputStream(), inputFile.getFileName()), true);
        } else { // assume file is not null (this is existing behaviour as of 1.5.1)
            request.field(fieldName, new FileContainer(inputFile), true);
        }
    }
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
358509
def file_link(self, instance):
        '''
            
        '''
        sfile = instance.file_upload
        if not sfile:
            return mark_safe('No file submitted by student.')
        else:
            return mark_safe('<a href="%s">%s</a><br/>(<a href="%s" target="_new">Preview</a>)' % (sfile.get_absolute_url(), sfile.basename(), sfile.get_preview_url()))
1011710
def ajax_upload(self, request, folder_id=None):
        
        mimetype = "application/json" if request.is_ajax() else "text/html"
        content_type_key = 'content_type'
        response_params = {content_type_key: mimetype}
        folder = None
        if folder_id:
            try:
                # Get folder
                folder = Folder.objects.get(pk=folder_id)
            except Folder.DoesNotExist:
                return HttpResponse(json.dumps({'error': NO_FOLDER_ERROR}),
                                    **response_params)

        # check permissions
        if folder and not folder.has_add_children_permission(request):
            return HttpResponse(
                json.dumps({'error': NO_PERMISSIONS_FOR_FOLDER}),
                **response_params)
        try:
            if len(request.FILES) == 1:
                # dont check if request is ajax or not, just grab the file
                upload, filename, is_raw = handle_request_files_upload(request)
            else:
                # else process the request as usual
                upload, filename, is_raw = handle_upload(request)

            # Get clipboad
            # TODO: Deprecated/refactor
            # clipboard = Clipboard.objects.get_or_create(user=request.user)[0]

            # find the file type
            for filer_class in media_settings.MEDIA_FILE_MODELS:
                FileSubClass = load_object(filer_class)
                # TODO: What if there are more than one that qualify?
                if FileSubClass.matches_file_type(filename, upload, request):
                    FileForm = modelform_factory(
                        model=FileSubClass,
                        fields=('original_filename', 'owner', 'file')
                    )
                    break
            uploadform = FileForm({'original_filename': filename,
                                   'owner': request.user.pk},
                                  {'file': upload})
            if uploadform.is_valid():
                file_obj = uploadform.save(commit=False)
                # Enforce the FILER_IS_PUBLIC_DEFAULT
                file_obj.is_public = settings.MEDIA_IS_PUBLIC_DEFAULT
                file_obj.folder = folder
                file_obj.save()
                # TODO: Deprecated/refactor
                # clipboard_item = ClipboardItem(
                #    clipboard=clipboard, file=file_obj)
                # clipboard_item.save()
                json_response = {
                    'thumbnail': file_obj.icons['32'],
                    'alt_text': '',
                    'label': str(file_obj),
                    'file_id': file_obj.pk,
                }
                return HttpResponse(json.dumps(json_response),
                                    **response_params)
            else:
                form_errors = '; '.join(['%s: %s' % (
                    field,
                    ', '.join(errors)) for field, errors in list(uploadform.errors.items())
                ])
                raise UploadException(
                    "AJAX request not valid: form invalid '%s'" % (form_errors,))
        except UploadException as e:
            return HttpResponse(json.dumps({'error': str(e)}),
                                **response_params)
337175
def param_upload(field, path):
    
    if not path:
        return None
    param = {}
    param['field'] = field
    param['path'] = path
    return param
1131151
def upload_file(fapi, file_name, conf):
    
    if not conf.has_key('file-type'):
        raise SmarterlingError("%s doesn't have a file-type" % file_name)
    print("Uploading %s to smartling" % file_name)
    data = UploadData(
        os.path.dirname(file_name)+os.sep,
        os.path.basename(file_name),
        conf.get('file-type'))
    data.setUri(file_uri(file_name, conf))
    if conf.has_key('approve-content'):
        data.setApproveContent("true" if conf.get('approve-content', True) else "false")
    if conf.has_key('callback-url'):
        data.setCallbackUrl(conf.get('callback-url'))
    for name, value in conf.get('directives', {}).items():
        data.addDirective(SmartlingDirective(name, value))
    (response, code) = fapi.upload(data)
    if code!=200:
        print(repr(response))
        raise SmarterlingError("Error uploading file: %s" % file_name)
    else:
        print("Uploaded %s, wordCount: %s, stringCount: %s" % (file_name, response.data.wordCount, response.data.stringCount))
455541
function uploadFileClientSide() {
        // if (typeof window.FileReader === 'undefined') {
        //      alert('The File APIs are not fully supported in this browser.');
        // }
        var $upload = $("input:file");

        $upload.change(function (e) {
            e.stopPropagation();
            e.preventDefault();

            renderImportedFile($upload.get(0).files[0]);
            return false;
        });
    }
636213
def to_file(file_):
        
        from sevenbridges.models.file import File
        if not file_:
            raise SbgError('File is required!')
        elif isinstance(file_, File):
            return file_.id
        elif isinstance(file_, six.string_types):
            return file_
        else:
            raise SbgError('Invalid file parameter!')
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
23545
def upload_image(self, media_file):
        
        res = self._post(
            url='media/uploadimg',
            files={
                'media': media_file
            },
            result_processor=lambda x: x['url']
        )
        return res
333698
def upload_resumable(self, fd, filesize, filehash, unit_hash, unit_id,
                         unit_size, quick_key=None, action_on_duplicate=None,
                         mtime=None, version_control=None, folder_key=None,
                         filedrop_key=None, path=None, previous_hash=None):
        
        action = 'upload/resumable'

        headers = {
            'x-filesize': str(filesize),
            'x-filehash': filehash,
            'x-unit-hash': unit_hash,
            'x-unit-id': str(unit_id),
            'x-unit-size': str(unit_size)
        }

        params = QueryParams({
            'quick_key': quick_key,
            'action_on_duplicate': action_on_duplicate,
            'mtime': mtime,
            'version_control': version_control,
            'folder_key': folder_key,
            'filedrop_key': filedrop_key,
            'path': path,
            'previous_hash': previous_hash
        })

        upload_info = {
            "fd": fd,
            "filename": "chunk"
        }

        return self.request(action, params, action_token_type="upload",
                            upload_info=upload_info, headers=headers)
1118881
def get_method_returning_field_value(self, field_name):
        
        method = getattr(self, field_name, None)
        return method if method and callable(method) else None
1371057
public function uploadField(UploadField $uploadField)
    {
        $tag = new Tag('input');
        $tag->setAttribute('type', 'file');
        $tag->setAttribute('accept', $uploadField->getAccept());
        if ($uploadField->isMultiple()) {
            $tag->setAttribute('multiple', 'multiple');
        }


        return $this->parseTag($tag, $uploadField);
    }
117582
protected function getUploadFileField($sField, $sFakeField)
    {
        $obFile = $this->getAttribute($sField);
        if (!empty($obFile)) {
            return $obFile;
        }

        $arFileData = $this->getAttribute($sFakeField);
        $obFile = $this->initUploadFileObject($arFileData);
        $this->setAttribute($sField, $obFile);

        return $obFile;
    }