Creates a new inline result of photo type.

        Args:
            file (`obj`, optional):
                Same as ``file`` for `client.send_file
                <telethon.client.uploads.UploadMethods.send_file>`.
168041
async def photo(
            self, file, *, id=None,
            text=None, parse_mode=(), link_preview=True,
            geo=None, period=60, contact=None, game=False, buttons=None
    ):
        
        try:
            fh = utils.get_input_photo(file)
        except TypeError:
            fh = await self._client.upload_file(file, use_cache=types.InputPhoto)

        if not isinstance(fh, types.InputPhoto):
            r = await self._client(functions.messages.UploadMediaRequest(
                types.InputPeerSelf(), media=types.InputMediaUploadedPhoto(fh)
            ))
            fh = utils.get_input_photo(r.photo)

        result = types.InputBotInlineResultPhoto(
            id=id or '',
            type='photo',
            photo=fh,
            send_message=await self._message(
                text=text or '',
                parse_mode=parse_mode,
                link_preview=link_preview,
                geo=geo,
                period=period,
                contact=contact,
                game=game,
                buttons=buttons
            )
        )
        if id is None:
            result.id = hashlib.sha256(bytes(result)).hexdigest()

        return result
397073
def handle_uploaded_file(file, folder=None, is_public=True):
    '''
    '''
    _folder = None

    if folder and isinstance(folder, Folder):
        _folder = folder
    elif folder:
        _folder, folder_created = Folder.objects.get_or_create(
            name=folder)

    for cls in MEDIA_MODELS:
        if cls.matches_file_type(file.name):

            obj, created = cls.objects.get_or_create(
                original_filename=file.name,
                file=file,
                folder=_folder,
                is_public=is_public)

            if created:
                return obj

    return None
9133
protected UploadFile convertUploadFile(File file) {
        Date lastModifiedDate = new Date();
        // Avoid parsing error on last modified date
        if (file.lastModifiedDate != null && !file.lastModifiedDate.isEmpty()) {
            lastModifiedDate = new Date(file.lastModifiedDate);
        }
        return new UploadFile(file.name, lastModifiedDate, Double.parseDouble(file.size), file.type);
    }
203705
def import_file(self, file_obj, folder):
        
        created = False
        for cls in MEDIA_MODELS:
            if cls.matches_file_type(file_obj.name):

                obj, created = cls.objects.get_or_create(
                    original_filename=file_obj.name,
                    file=file_obj,
                    folder=folder,
                    is_public=FILER_IS_PUBLIC_DEFAULT)
                if created:
                    self.image_created += 1
        if not created:
            obj, created = File.objects.get_or_create(
                original_filename=file_obj.name,
                file=file_obj,
                folder=folder,
                is_public=FILER_IS_PUBLIC_DEFAULT)
            if created:
                self.file_created += 1
        if self.verbosity >= 2:
            print("file_created #%s / image_created #%s -- file : %s -- created : %s" % (self.file_created,
                                                                                         self.image_created,
                                                                                         obj, created))
        return obj
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();
	}
1153324
def upload_from_url(self, url, **kwds):
        
        result = self._client.post("/photo/upload.json", photo=url,
                                   **kwds)["result"]
        return Photo(self._client, result)
47567
private void uploadNewVersion(final BoxFile file) {
        new Thread() {
            @Override
            public void run() {
                try {
                    String uploadFileName = "box_logo.png";
                    InputStream uploadStream = getResources().getAssets().open(uploadFileName);
                    BoxRequestsFile.UploadNewVersion request = mFileApi.getUploadNewVersionRequest(uploadStream, file.getId());
                    final BoxFile uploadFileVersionInfo = request.send();
                    showToast("Uploaded new version of " + uploadFileVersionInfo.getName());
                } catch (IOException e) {
                    e.printStackTrace();
                } catch (BoxException e) {
                    e.printStackTrace();
                    showToast("Upload failed");
                } finally {
                    mDialog.dismiss();
                }
            }
        }.start();
    }
387741
def open_file(self, file_):
        
        with open(file_, 'r', encoding='utf-8') as file:
            text = ''
            for line in file:
                text += line
        return text
182070
function(file, callback, quality) {
		quality = !quality?85:quality;
		
		var data = this.jpeg_encode.encode(this, quality);
		
		var fd =  this.fs.openSync(file, 'w');
		var bf = new Buffer(data);
		
		this.fs.writeSync(fd, bf, 0, bf.length);
		this.fs.closeSync(fd);
		
		if(callback) {
			callback.call(this);
		}
	}
1133017
def replace(self, photo, photo_file, **kwds):
        
        with open(photo_file, 'rb') as in_file:
            result = self._client.post("/photo/%s/replace.json" %
                                       self._extract_id(photo),
                                       files={'photo': in_file},
                                       **kwds)["result"]
        return Photo(self._client, result)
628339
def _inline_image(image, mime_type=None):
    
    file = StringValue(image).value
    mime_type = StringValue(mime_type).value or mimetypes.guess_type(file)[0]
    path = None
    if callable(STATIC_ROOT):
        try:
            _file, _storage = list(STATIC_ROOT(file))[0]
            path = _storage.open(_file)
        except:
            pass
    else:
        _path = os.path.join(STATIC_ROOT, file)
        if os.path.exists(_path):
            path = open(_path, 'rb')
    if path:
        url = 'data:' + mime_type + ';base64,' + base64.b64encode(path.read())
    url = url = '%s%s?_=%s' % (STATIC_URL, file, 'NA')
    inline = 'url("%s")' % escape(url)
    return StringValue(inline)
869122
def create_image(self, image_file, caption):
        
        suffix = 'png'
        if image_file:
            img = Image.open(os.path.join(self.gallery, image_file))
            width, height = img.size
            ratio = width/WIDTH
            img = img.resize((int(width // ratio),
                              int(height // ratio)),
                             Image.ANTIALIAS)
        else:
            img = Image.new('RGB', (WIDTH, HEIGHT), 'black')
            image = self.add_caption(img, caption)
            
        image = img

        return image
1202287
function (file) {
                var _this = this;
                return new Promise(function (resolve, reject) {
                    return __awaiter(_this, void 0, void 0, function () {
                        var err_1, err_2;
                        var _this = this;
                        return __generator(this, function (_a) {
                            switch (_a.label) {
                                case 0:
                                    this.processing.emit(true);
                                    _a.label = 1;
                                case 1:
                                    _a.trys.push([1, 3, , 4]);
                                    return [4 /*yield*/, this.readImage(file)];
                                case 2:
                                    _a.sent();
                                    return [3 /*break*/, 4];
                                case 3:
                                    err_1 = _a.sent();
                                    console.error(err_1);
                                    this.error.emit(new Error(err_1));
                                    return [3 /*break*/, 4];
                                case 4:
                                    _a.trys.push([4, 6, , 7]);
                                    return [4 /*yield*/, this.showPreview()];
                                case 5:
                                    _a.sent();
                                    return [3 /*break*/, 7];
                                case 6:
                                    err_2 = _a.sent();
                                    console.error(err_2);
                                    this.error.emit(new Error(err_2));
                                    return [3 /*break*/, 7];
                                case 7:
                                    // set pane limits
                                    // show points
                                    this.imageLoaded = true;
                                    return [4 /*yield*/, this.limitsService.setPaneDimensions({ width: this.previewDimensions.width, height: this.previewDimensions.height })];
                                case 8:
                                    _a.sent();
                                    setTimeout(function () {
                                        return __awaiter(_this, void 0, void 0, function () {
                                            return __generator(this, function (_a) {
                                                switch (_a.label) {
                                                    case 0: return [4 /*yield*/, this.detectContours()];
                                                    case 1:
                                                        _a.sent();
                                                        this.processing.emit(false);
                                                        resolve();
                                                        return [2 /*return*/];
                                                }
                                            });
                                        });
                                    }, 15);
                                    return [2 /*return*/];
                            }
                        });
                    });
                });
            }
45318
function (file) {
                var _this = this;
                return new Promise(function (resolve, reject) {
                    return __awaiter(_this, void 0, void 0, function () {
                        var imageSrc, err_3, img;
                        var _this = this;
                        return __generator(this, function (_a) {
                            switch (_a.label) {
                                case 0:
                                    _a.trys.push([0, 2, , 3]);
                                    return [4 /*yield*/, readFile()];
                                case 1:
                                    imageSrc = _a.sent();
                                    return [3 /*break*/, 3];
                                case 2:
                                    err_3 = _a.sent();
                                    reject(err_3);
                                    return [3 /*break*/, 3];
                                case 3:
                                    img = new Image();
                                    img.onload = function () {
                                        return __awaiter(_this, void 0, void 0, function () {
                                            var ctx, width, _a;
                                            return __generator(this, function (_b) {
                                                switch (_b.label) {
                                                    case 0:
                                                        // set edited image canvas and dimensions
                                                        this.editedImage = ( /** @type {?} */(document.createElement('canvas')));
                                                        this.editedImage.width = img.width;
                                                        this.editedImage.height = img.height;
                                                        ctx = this.editedImage.getContext('2d');
                                                        ctx.drawImage(img, 0, 0);
                                                        // resize image if larger than max image size
                                                        width = img.width > img.height ? img.height : img.width;
                                                        if (!(width > this.options.maxImageDimensions.width))
                                                            return [3 /*break*/, 2];
                                                        _a = this;
                                                        return [4 /*yield*/, this.resize(this.editedImage)];
                                                    case 1:
                                                        _a.editedImage = _b.sent();
                                                        _b.label = 2;
                                                    case 2:
                                                        this.imageDimensions.width = this.editedImage.width;
                                                        this.imageDimensions.height = this.editedImage.height;
                                                        this.setPreviewPaneDimensions(this.editedImage);
                                                        resolve();
                                                        return [2 /*return*/];
                                                }
                                            });
                                        });
                                    };
                                    img.src = imageSrc;
                                    return [2 /*return*/];
                            }
                        });
                    });
                });
                /**
                 * read file from input field
                 * @return {?}
                 */
                function readFile() {
                    return new Promise(function (resolve, reject) {
                        /** @type {?} */
                        var reader = new FileReader();
                        reader.onload = function (event) {
                            resolve(reader.result);
                        };
                        reader.onerror = function (err) {
                            reject(err);
                        };
                        reader.readAsDataURL(file);
                    });
                }
            }
600393
public void sendFile(File file, OutputStream os) throws IOException {
        FileInputStream is = null;
        BufferedInputStream buf = null;;
        try {
            is = new FileInputStream(file);
            buf = new BufferedInputStream(is);
            int readBytes = 0;
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Writing file...");
            }
            while ((readBytes = buf.read()) != -1) {
                os.write(readBytes);
            }
            os.flush();
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("File written");
            }
        } finally {
            if (is != null) {
                is.close();
            }
            if (buf != null) {
                buf.close();
            }
        }
    }
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
915492
async def send_photo(self, path, entity):
        """"""
        await self.send_file(
            entity, path,
            progress_callback=self.upload_progress_callback
        )
        print('Photo sent!')