Convenience method to upload files to the server. User to upload media.

@param uri the URI
@param sourceFile the source file
@param contentType the content type.
@throws IOException unexpected exception.
@throws AppPlatformException unexpected exception.
506011
public void upload(final String uri, final File sourceFile, final String contentType)
            throws IOException, AppPlatformException {
        final String path = getPath(uri);
        final HttpPut request = (HttpPut) setupRequest(path, HttpPut.METHOD_NAME, null);
        request.setEntity(contentType == null ? new FileEntity(sourceFile) : new FileEntity(sourceFile, ContentType.parse(contentType)));
        performRequest(request);
    }
576817
protected final void initializeMediaUpload(AbstractInputStreamContent mediaContent) {
    HttpRequestFactory requestFactory = abstractGoogleClient.getRequestFactory();
    this.uploader = new MediaHttpUploader(
        mediaContent, requestFactory.getTransport(), requestFactory.getInitializer());
    this.uploader.setInitiationRequestMethod(requestMethod);
    if (httpContent != null) {
      this.uploader.setMetadata(httpContent);
    }
  }
576670
protected void uploadFile() {

        hideOkAndUploadButtons();
        CmsUploader uploader = new CmsUploader();
        CmsFileInfo info = m_fileInput.getFiles()[0];
        info.setOverrideFileName(CmsResource.getName(m_replaceInfo.getSitepath()));
        uploader.uploadFiles(
            CmsCoreProvider.get().link(I_CmsUploadConstants.UPLOAD_ACTION_JSP_URI),
            CmsResource.getFolderPath(m_replaceInfo.getSitepath()),
            false,
            Collections.singletonList(info),
            Collections.<String> emptyList(),
            this);
        showProgress();
    }
654982
public static void toFile(final HttpConfig config, final String contentType, final File file) {
        config.context(contentType, ID, file);
        config.getResponse().parser(contentType, Download::fileParser);
    }
126205
public void startPart(String contentType)
         throws IOException
    {
        if (inPart)
            out.write(__CRLF);
        inPart=true;
        out.write(__DASHDASH);
        out.write(boundaryBytes);
        out.write(__CRLF);
        out.write(("Content-Type: "+contentType).getBytes(StringUtil.__ISO_8859_1));
        out.write(__CRLF);
        out.write(__CRLF);
    }
446496
public String put(File file) throws IOException {

        if (!connection.isOpen())
            connection.open();

        connection.prepare("PUT");

        String contentType = connection.getHeader("Content-Type");
        if (contentType == null)
            contentType = connection.getHeader("content-type");
        if (contentType == null || contentType.isEmpty()) {
            /**
             * Default it to application/octet-stream if nothing has been specified
             */
            connection.setHeader("Content-Type", "application/octet-stream");
        }

        OutputStream outStream = connection.getOutputStream();
        InputStream inStream = new FileInputStream(file);

        byte[] buf = new byte[1024];
        int len = 0;
        while (len != -1)
        {
          len = inStream.read(buf);
          if (len > 0)
            outStream.write(buf, 0, len);
        }

        inStream.close();
        outStream.close();

        BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getConnection().getInputStream()));
        StringBuffer responseBuffer = new StringBuffer();
        String line = null;
        while ((line = reader.readLine()) != null) {
            responseBuffer.append(line).append('\n');
        }

        reader.close();

        connection.getConnection().disconnect();

        response = new HttpResponse(responseBuffer.toString().getBytes());
        response.setCode(connection.getConnection().getResponseCode());
        if (response.getCode() < 200 || response.getCode() >= 300)
        {
            response.setMessage(connection.getConnection().getResponseMessage());
            throw new IOException("Error uploading file: " + response.getCode() + " -- " + response.getMessage());
        }

        return getResponse();
    }
735921
private void putFile(String name, UploadFile uploadFile) {
		UploadFile[] fileUploads = requestFiles.get(name);
		fileUploads = fileUploads == null ? new UploadFile[] { uploadFile } : ArrayUtil.append(fileUploads, uploadFile);
		requestFiles.put(name, fileUploads);
	}
1303813
public static void updateFileFromFile(final File sourceFile, final String destinationFilePath) throws
        UpdateException {
        if (!sourceFile.exists()) {
            throw new UpdateException("Source file does not exist: " + sourceFile);
        }
        if (!sourceFile.isFile()) {
            throw new UpdateException("Not a file: " + sourceFile);
        }
        if (sourceFile.length() < 1) {
            throw new UpdateException("Source file is empty: " + sourceFile);
        }

        try {
            updateFileFromInputStream(new FileInputStream(sourceFile), destinationFilePath);
        } catch (IOException e) {
            throw new UpdateException("Unable to update file: " + e.getMessage(), e);
        }
    }
1049952
def _upload(self, archive, region):
        
        # Generate source upload url
        url = self.client.execute_command(
            'generateUploadUrl',
            {'parent': 'projects/{}/locations/{}'.format(
                self.session.get_default_project(),
                region)}).get('uploadUrl')
        log.debug("uploading function code %s", url)
        http = self._get_http_client(self.client)
        headers, response = http.request(
            url, method='PUT',
            headers={
                'content-type': 'application/zip',
                'Content-Length': '%d' % archive.size,
                'x-goog-content-length-range': '0,104857600'
            },
            body=open(archive.path, 'rb')
        )
        log.info("function code uploaded")
        if headers['status'] != '200':
            raise RuntimeError("%s\n%s" % (headers, response))
        return url
1328806
public void startPart(String contentType) throws IOException {
        if (inPart)
            out.write(__CRLF);
        inPart = true;
        out.write(__DASHDASH);
        out.write(boundaryBytes);
        out.write(__CRLF);
        if (contentType != null)
            out.write(("Content-Type: " + contentType).getBytes(StandardCharsets.ISO_8859_1));
        out.write(__CRLF);
        out.write(__CRLF);
    }
287830
@RequestMapping(value = "/upload.action", method = RequestMethod.POST)
    public ResponseEntity<?> uploadFile(
        @RequestParam("file") MultipartFile uploadedFile) {

        LOG.debug("Requested to upload a multipart-file");

        // build response map
        Map<String, Object> responseMap = new HashMap<String, Object>();
        try {
            E file = service.uploadFile(uploadedFile);
            LOG.info("Successfully uploaded file " + file.getFileName());
            responseMap = ResultSet.success(file);
        } catch (Exception e) {
            LOG.error("Could not upload the file: " + e.getMessage());
            responseMap = ResultSet.error("Could not upload the file: " +
                e.getMessage());
        }

        final HttpHeaders responseHeaders = new HttpHeaders();
        responseHeaders.setContentType(MediaType.APPLICATION_JSON_UTF8);

        // rewrite the response-Map as String
        return new ResponseEntity<>(responseMap, responseHeaders, HttpStatus.OK);
    }
438111
public static void copyFile(File sourceFile, File destinationFile) throws FileNotFoundException, IOException {
		Streams.copyStream(new FileInputStream(sourceFile), new FileOutputStream(destinationFile), true);
	}
682235
public InputStream doPost(byte[] postData, String contentType) {
        this.urlConnection.setDoOutput(true);
        if (contentType != null) this.urlConnection.setRequestProperty( "Content-type", contentType );

        OutputStream out = null;
        try {
            out = this.getOutputStream();
            if(out!=null)
            {
                out.write(postData);
                out.flush();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if(out!=null)
                try {
                    out.close();
                } catch (IOException e) {
                    //
                }
        }


        return (this.getInputStream());
    }
611541
public void uploadRepository(String name, File archive)
			throws ClientException {

		HttpPut putMethod = new HttpPut(baseUri + "/repository/"
				+ encodeURIComponent(name));

		HttpEntity httpEntity = MultipartEntityBuilder
				.create()
				.addBinaryBody("file", archive,
						ContentType.create("application/zip"),
						archive.getName()).build();

		putMethod.setEntity(httpEntity);

		try {
			CloseableHttpResponse result = httpClient.execute(putMethod);
			try {
				StatusLine status = result.getStatusLine();
				if (status.getStatusCode() != HttpStatus.SC_CREATED) {
					throw new APICallException(EntityUtils.toString(result
							.getEntity()), status.getStatusCode());
				}
			} finally {
				result.close();
			}
		} catch (HttpResponseException e) {
			throw new APICallException(e.getMessage(), e.getStatusCode());

		} catch (IOException e) {
			throw new NotAvailableException(e);
		}
	}
174756
public void doHttpPost(String url, HttpResponse result, Map<String, Object> headers, String contentType) {
        httpClient.post(url, result, headers, contentType);
    }
1302737
public void put(String remoteFileName,
                    DataSource source,
                    MarkerListener mListener)
        throws IOException, ServerException, ClientException {
        put(remoteFileName, source, mListener, false);
    }
696993
public void uploadFile(String Key, File File) throws QiniuException {
    com.qiniu.http.Response response =
        mUploadManager.put(File, Key, mAuth.uploadToken(mBucketName, Key));
    response.close();
  }