Upload an image to Imgur

@param string File you will be uploading (URL, Binary, Base64)
@param int Album ID to upload the file in
@param string Name of image
@param string Title of image
@param string Description of image
@return mixed Response
485034
public function upload($file, $format = 'json', $album = null, $name = null, $title = null, $description = null)
	{
		return $this->post('https://api.imgur.com/3/image.' . $format, array(
			'image' => $file,
			'album' => $album,
			'name' => $name,
			'title' => $title,
			'description' => $description
		), array(
			'Authorization: Client-ID ' . $this->key
		));
	}
684577
def upload_file(self, file):
        """"""

        url = self._get_url('/api/1.0/upload/post')

        fcontent = FileContent(file)
        binary_data = fcontent.get_binary()

        headers = self._get_request_headers()
        req = urllib.request.Request(url, binary_data, headers)
        req.add_header('Content-type', fcontent.get_content_type())
        req.add_header('Content-length', len(binary_data))
        resp = urllib.request.urlopen(req)   

        return definition.UploadPostResponse(_response_to_json(resp))
188630
public function file(string $file, string $name = null, bool $download = true): ResponseInterface
    {
        if (!\is_file($file)) {
            throw new \LogicException("File '$file' doesn't exist.");
        }

        $extension = \substr($file, \strrpos($file, '.') + 1);
        $this->header->set('Content-Type',
            MimeType::getMimeType($extension) ?? 'application/octet-stream'
        );

        $disposition = $download ? Header::DISPOSITION_ATTACHMENT : Header::DISPOSITION_INLINE;
        $this->header->set('Content-Disposition',
            $this->header->makeDisposition($disposition, $name, \basename($file))
        );

        $size = $length = \filesize($file);

        $this->header->set('Accept-Ranges', 'bytes');
        if (\preg_match('#^bytes=(\d*)-(\d*)\z#', $this->request->header('Range'), $matches)) {
            list(, $start, $end) = $matches;

            if ($start === '') {
                $start = \max(0, $size - $end);
                $end = $size - 1;
            } elseif ($end === '' || $end > $size - 1) {
                $end = $size - 1;
            }

            if ($end < $start) {
                return $this->empty(416); // requested range not satisfiable
            }

            $this->setStatus(206);
            $this->header->set('Content-Range', 'bytes ' . $start . '-' . $end . '/' . $size);
            $length = $end - $start + 1;
        } else {
            $this->header->set('Content-Range', 'bytes 0-' . ($size - 1) . '/' . $size);
        }

        $this->header->set('Content-Length', $length);

        $this->app->emitter(
            $this->emitter ?? Emitter\SapiStream::class
        );

        return $this->response(
            Factory::streamFromFile($file, 'rb')
        );
    }
45305
def post_image(url, filename)
      post(url) do |req|
        req.body = open(filename).read
      end
    end
1351353
function (file, callback) {

                var self = this,
                    reader = new FileReader();

                var uploadDesign = this.$.imageUploadService.upload(file, function (err) {
                    if (!err) {
                        self.trigger("uploadComplete", {
                            uploadDesign: uploadDesign
                        });
                    } else {
                        self.trigger("uploadError", {
                            error: err,
                            uploadDesign: uploadDesign
                        });
                    }

                    callback && callback(err, uploadDesign);
                });

                reader.onload = function(evt) {

                    var img = new Image();
                    img.onload = function() {
                        uploadDesign.set({
                            previewImage: evt.target.result,
                            localImage: evt.target.result
                        });
                    };
                    img.src = evt.target.result;
                };

                reader.readAsDataURL(file);


                return uploadDesign;
            }
1245206
public static function uploadFiles($field, $title, $action, array $value = [])
    {
        return self::upload($field, $title, $action, $value, Upload::TYPE_FILE);
    }
789075
public function upload($file)
    {
        $zip = new Zip();
        $zip->addFile($file);

        $response = $this->browser->request('POST', 'file', json_encode(array('file' => base64_encode($zip->getContent()))));
        $content  = json_decode($response->getContent(), true);

        if (!isset($content['value'])) {
            throw new LibraryException('Malformed expression, no key "value" in response: '.$response->getContent());
        }

        $file = $content['value'];

        $this->type($file);

        return $file;
    }
1201947
def add_metadata(file_name, title, artist, album):
    
    
    tags = EasyMP3(file_name)
    if title: 
        tags["title"] = title
    if artist:     
        tags["artist"] = artist
    if album:
        tags["album"] = album
    tags.save()

    return file_name
1339899
public function upload($name)
    {
        $instance = $this->_getInstance($name);
        require_once Plugin::classPath('Field') . 'Lib/class.upload.php';
        $uploader = new \upload($this->request->data['Filedata']);

        if (!empty($instance->settings['extensions'])) {
            $exts = explode(',', $instance->settings['extensions']);
            $exts = array_map('trim', $exts);
            $exts = array_map('strtolower', $exts);

            if (!in_array(strtolower($uploader->file_src_name_ext), $exts)) {
                $this->_error(__d('field', 'Invalid file extension.'), 501);
            }
        }

        $response = '';
        $uploader->file_overwrite = false;
        $folder = normalizePath(WWW_ROOT . "/files/{$instance->settings['upload_folder']}/");
        $url = normalizePath("/files/{$instance->settings['upload_folder']}/", '/');

        $uploader->process($folder);
        if ($uploader->processed) {
            $response = json_encode([
                'file_url' => Router::url($url . $uploader->file_dst_name, true),
                'file_size' => FileToolbox::bytesToSize($uploader->file_src_size),
                'file_name' => $uploader->file_dst_name,
                'mime_icon' => FileToolbox::fileIcon($uploader->file_src_mime),
            ]);
        } else {
            $this->_error(__d('field', 'File upload error, details: {0}', $uploader->error), 502);
        }

        $this->viewBuilder()->layout('ajax');
        $this->title(__d('field', 'Upload File'));
        $this->set(compact('response'));
    }
83301
public function Upload ($file)
	{
		
		// Set uploaded file
		
		$this->upload	= $file;
		
		// If there is an upload error
		
		if ($this->upload['error'] != UPLOAD_ERR_OK)
		{
			
			// Set error
			
			new \Sonic\Message ('error', self::_uploadError ($this->upload['error']));
			
			// Return FALSE
			
			return FALSE;
			
		}
		
		// Set file details
		
		$this->filename		= $this->upload['name'];
		$this->extension	= self::_getExtension ($this->filename);
		$this->name			= self::_getFilename ($this->filename);
		
		// Return TRUE
		
		return TRUE;
		
	}
290746
public function send_file($file) {
        // First we create the 'resumable upload request'.
        $this->googleoauth->setHeader("Content-Length: 0");
        $this->googleoauth->setHeader("X-Upload-Content-Length: ". $file->get_filesize());
        $this->googleoauth->setHeader("X-Upload-Content-Type: ". $file->get_mimetype());
        $this->googleoauth->setHeader("Slug: ". $file->get_filename());
        $this->googleoauth->post(self::UPLOAD_URL);

        if ($this->googleoauth->info['http_code'] !== 200) {
            throw new moodle_exception('Cantpostupload');
        }

        // Now we http PUT the file in the location returned.
        $location = $this->googleoauth->response['Location'];
        if (empty($location)) {
            throw new moodle_exception('Nouploadlocation');
        }

        // Reset the curl object for actually sending the file.
        $this->reset_curl_state();
        $this->googleoauth->setHeader("Content-Length: ". $file->get_filesize());
        $this->googleoauth->setHeader("Content-Type: ". $file->get_mimetype());

        // We can't get a filepointer, so have to copy the file..
        $tmproot = make_temp_directory('googledocsuploads');
        $tmpfilepath = $tmproot.'/'.$file->get_contenthash();
        $file->copy_content_to($tmpfilepath);

        // HTTP PUT the file.
        $this->googleoauth->put($location, array('file'=>$tmpfilepath));

        // Remove the temporary file we created..
        unlink($tmpfilepath);

        if ($this->googleoauth->info['http_code'] === 201) {
            // Clear headers for further requests.
            $this->reset_curl_state();
            return true;
        } else {
            return false;
        }
    }
1189113
public function addImage(string $image)
    {
        $url = self::ADD_IMAGE.$this->access_token;
        $this->curl->setOpt(CURLOPT_SAFE_UPLOAD, true);

        return Response::json($this->curl->post($url, [
            'media' => new \CURLFile($image),
        ]));
    }
1264031
public function display_uploaded_file($file)
    {
        if (empty($file)) {
            return;
        }

        $file = $this->plugins->exec_hook('attachment_display', $file);

        if ($file['status']) {
            if (empty($file['size'])) {
                $file['size'] = $file['data'] ? strlen($file['data']) : @filesize($file['path']);
            }

            // generate image thumbnail for file browser in HTML editor
            if (!empty($_GET['_thumbnail'])) {
                $temp_dir       = $this->config->get('temp_dir');
                $thumbnail_size = 80;
                $mimetype       = $file['mimetype'];
                $file_ident     = $file['id'] . ':' . $file['mimetype'] . ':' . $file['size'];
                $cache_basename = $temp_dir . '/' . md5($file_ident . ':' . $this->user->ID . ':' . $thumbnail_size);
                $cache_file     = $cache_basename . '.thumb';

                // render thumbnail image if not done yet
                if (!is_file($cache_file)) {
                    if (!$file['path']) {
                        $orig_name = $filename = $cache_basename . '.tmp';
                        file_put_contents($orig_name, $file['data']);
                    }
                    else {
                        $filename = $file['path'];
                    }

                    $image = new rcube_image($filename);
                    if ($imgtype = $image->resize($thumbnail_size, $cache_file, true)) {
                        $mimetype = 'image/' . $imgtype;

                        if ($orig_name) {
                            unlink($orig_name);
                        }
                    }
                }

                if (is_file($cache_file)) {
                    // cache for 1h
                    $this->output->future_expire_header(3600);
                    header('Content-Type: ' . $mimetype);
                    header('Content-Length: ' . filesize($cache_file));

                    readfile($cache_file);
                    exit;
                }
            }

            header('Content-Type: ' . $file['mimetype']);
            header('Content-Length: ' . $file['size']);

            if ($file['data']) {
                echo $file['data'];
            }
            else if ($file['path']) {
                readfile($file['path']);
            }
        }
    }
21992
@Override
	public boolean upload(String path, File file) {
		Assert.notNull(file, "file to upload is null !");
		return upload(path, file.getName(), file);
	}
543999
public int uploadFile(String name, java.io.File file) {
		FileDataBodyPart filePart = new FileDataBodyPart("source", file);
		// Work around for bug in cherrypy
		FormDataContentDisposition.FormDataContentDispositionBuilder builder = FormDataContentDisposition
				.name(filePart.getName());
		builder.fileName(file.getName());
		builder.size(file.length());
		filePart.setFormDataContentDisposition(builder.build());

		FormDataMultiPart multiPart = new FormDataMultiPart();
		multiPart.bodyPart(filePart);
		multiPart.field("filename", name);

		Builder resource = getResourceFactory().getApiResource("/file/v2/")
				.entity(multiPart,
						new MediaType("multipart", "form-data", Collections
								.singletonMap("boundary", "AaB03x")));
		return resource.post(File.class).getId();
	}
37895
def update(self, title=None, description=None):
        """"""
        url = (self._imgur._base_url + "/3/image/"
               "{0}".format(self._delete_or_id_hash))
        is_updated = self._imgur._send_request(url, params=locals(),
                                               method='POST')
        if is_updated:
            self.title = title or self.title
            self.description = description or self.description
        return is_updated
58530
function (file, responseText) {
        console.log(responseText); // console should show the ID you pointed to
        // read the upload path from the elements data-upload attribute.
        var uploadPath = $(this.dropzone.element).data("upload") + responseText;
        var linkToUploadedFile = "(" + uploadPath + ")";
        if ( file.type.startsWith( "image/" ) ) {
            linkToUploadedFile = "![]" + linkToUploadedFile;
        } else {
            linkToUploadedFile = "[" + responseText + "]" + linkToUploadedFile;
        }
        this.simplemde.value(this.simplemde.value() + "\n" + linkToUploadedFile + "\n");
    }