working on it ...

Filters

Explore Public Snippets

Sort by

Found 6,507 snippets matching: upload

    public by clsw  350038  0  6  1

    Image upload to API, return direct link. (IMGUR)

    Imgur, one of the best image hosts in the world, has a fantastic API, this is a VERY simple and usable implementation of it, just pass an image to the function and it will return the direct link to yout image, heavily commented and easy to use.
    public string UploadImage(Image img)
            {
                //get a dev key from api.imgur.com, anonymous usage (no user auth) only.
                string devkey = "YOUR_CLIENT_ID (e.g. abcde1f234567g8)";
    
                //define the WebClient we'll use to communicate with Imgur.
                WebClient w = new WebClient();
                
                //adds the Header to authorize this application with Imgur, must include a valid CLIENT_ID from 'devkey' above.
                w.Headers.Add("Authorization", "Client-ID " + devkey);
    
                System.Collections.Specialized.NameValueCollection Keys = new System.Collections.Specialized.NameValueCollection();
                try
                {
                    //Converts the image to a byte array so it can be turned into a string for upload.
                    using (MemoryStream stream = new MemoryStream())
                    {
                        img.Save(stream, ImageFormat.Png);
                        Keys.Add("image", Convert.ToBase64String(stream.ToArray()));
                    }
                    
                    //uploads the string-formatted-image and waits for the response.
                    byte[] responseArray = w.UploadValues("https://api.imgur.com/3/image", Keys);
                    dynamic result = Encoding.ASCII.GetString(responseArray);
    
                    //formats the (long and technical) result into just the direct image link.
                    Regex reg = new Regex("link\":\"(.*?)\""); Match match = reg.Match(result);
                    string url = match.ToString().Replace("link\":\"", "").Replace("\"", "").Replace("\\/", "/");
    
                    //returns the online address of the image.
                    return url;
                }
                catch (Exception s) { MessageBox.Show(s.Message); return "err"; }
            }

    public by lbottaro @ Amazon_AWS_Python_API  304400  0  8  0

    Amazon S3 Aws - How to download a file from a bucket to a target directory

    This code shows how to download a file from an existing bucket invoking the boto python API, saving to a target directory. You need to specify the filename and path where to save the data. [How to create a bucket](http://www.snip2code.com/Snippet/4892/Amazon-Aws-S3---Creating-a-bucket-in-pyt) [How to upload a file to a bucket](http://www.sn
    # This downloads the object foobar.pdf and saves it in /home/luca/documents/
    
    key = bucket.get_key('foobar.pdf')
    key.get_contents_to_filename('/home/luca/documents/foobar.pdf')

    public by skaggej  237856  1  6  0

    SharePoint 2010 - Bulk Upload Solution Packages

    When migrating a SharePoint environment from 2007 to 2010, don't forget about your solution packages! You can extract them from the SharePoint 2007 Solution Store, then use this script to upload them all to SharePoint 2010 in seconds!
    $solutions = Get-ChildItem -Path "C:\downloads\Exported Solution Packages"
    $solutions | ForEach-Object {add-spsolution -literalpath "C:\Exported Solution Packages\$_"}

    public by johansonkatherine  219699  1  6  2

    C# Code Sample to Replace Multiple Texts inside PDF File Using Cloud API

    The following code sample shows how developers can replace multiple texts in a single API call in a PDF file using Aspose.Pdf for Cloud API in their applications. Developers can use Aspose REST API with any language: .NET, Java, PHP, Ruby, Rails, Python, jQuery and many more.
    AsposeApp.AppSID  = "77***********************************";
    AsposeApp.AppKey = "9a*******************************";
    
    //build URI
    stringstrURI = "http://api.aspose.com/v1.1/pdf/test.pdf/replaceTextList";
    
    //sign URI
    stringsignedURI = Utils.Sign(strURI);
    
    //build JSON to post
    TextReplace textReplace1 = new TextReplace();
    textReplace1.OldValue = "[!firm!]";
    textReplace1.NewValue = "Aspose";
    textReplace1.Regex = "false";
    
    //build JSON to post
    TextReplace textReplace2 = new TextReplace();
    textReplace2.OldValue = "[!client!]";
    textReplace2.NewValue = "Mark";
    textReplace2.Regex = "false";
    
    MultipleTextReplacestextReplaces = new MultipleTextReplaces();
    textReplaces.TextReplaces = new TextReplace[] { textReplace1, textReplace2 };
    stringstrJSON = JsonConvert.SerializeObject(textReplaces);
    Console.Write(strJSON);
    Utils.ProcessCommand(signedURI, "POST", strJSON);
    
    //build URI
    strURI = "http://api.aspose.com/v1.1/storage/file/test.pdf";
    
    //sign URI
    signedURI = Utils.Sign(strURI);
    
    Stream responseStream = Utils.ProcessCommand(signedURI, "GET");
    using (Stream fileStream = System.IO.File.OpenWrite(@"test.pdf"))
    {
    Utils.CopyStream(responseStream, fileStream);
    }
    responseStream.Close();
    
    //Following are required classes
    public class MultipleTextReplaces
        {
    publicTextReplace[] TextReplaces { get; set; }
        }
    public class TextReplace
        {
    publicTextReplace() { }
    
    public string OldValue { get; set; }
    public string NewValue { get; set; }
    public string Regex { get; set; }
    
        }
    

    public by mporru @ Amazon_AWS_PHP_API  210376  0  5  0

    Amazon AWS - PHP: Upload a File taking it from your server

    This snippet demonstrates how to upload a file to a S3 Bucket, taking it form a your server. In order to use this service you must enable Amazon Simple Storage Service (Amazon S3) in your account. Taken from: http://www.sitepoint.com/getting-started-with-the-aws-php-sdk/
    <?php
    require_once 'sdk.class.php';
    $s3 = new AmazonS3();
    // Create Object is pretty self explanatory:
    // Arg 1: The bucket where your file will be created.
    // Arg 2: The name of your file.
    // Arg 3: An array of Options.
    //        In this case we're specifying the &quot;fileUpload&quot; option (a file on your server)
    //        and the ACL setting to allow this file to be read by anyone.
    $response=$s3->create_object('myBucketName', 'LighthouseNew.jpg', 
    array('fileUpload'=>'./Lighthouse.jpg', 'acl'=>AmazonS3::ACL_PUBLIC));
    // Check if everything is okay.
    if ($response->isOK()) {
    	echo("File uploaded correctly");
    } else {
    	echo("There was an error uploading the file!");
    }
    ?>

    public by MarcoDeMagistris  3370  2  6  0

    Upload File

    Upload File MVC4 patterns
    Controller:
            public ActionResult Index()
            {
                return View();
            }
    
    Model: 
    		  private HttpPostedFileBase File { get; set; }
            #region PROPERTIES
            [Display(Name = "Upload your .txt File")]
            [FileExtensions(Extensions = "txt", ErrorMessage = "The file you selected is not a valid .txt file")]
            [Required(ErrorMessage = ".txt file not selected")]
            public HttpPostedFileBase File1
            {
                get { return this.File; }
                set { this.File = value; }
            }
    		#endregion
    
    Views:
    
    	<div id="Componentsdiv">
        @using (Html.BeginForm(<action>, <Controller>, FormMethod.Post, new { enctype = "multipart/form-data" }))
        {
            <fieldset>
                <legend>Upload TXT File</legend>
    
                <div class="editor-label">
                    <fieldset>
                    <legend>File</legend>
                        @Html.TextBoxFor(m => m.File1, "Select new file", new {  id="firstfile", type = "file"})
                        @Html.ValidationMessageFor(m => m.File1)
                    </fieldset>
                </div>
                <p>
                    <input type="submit" id="submitbutton" hidden="hidden"/>
                </p>
            </fieldset>
        }
        </div>

    public by micurs  2664  0  6  1

    Upload a file into a S3 bucket in Python

    Uploading a local file into S3 using the Boto library is pretty simple. In this example we upload the localFilepath into a destS3Name location in the destBucket. Here is the snippet:
    s3Link = S3Connection()
    s3Bucket = s3Link.get_bucket(destBucket)
    
    newItem = s3Bucket.new_key(destS3Name)
    newItem.set_contents_from_filename(localFilepath)
    
    

    public by Kingsley Huynh  5540  29  5  0

    Golang HTTP Handler to Upload Image => Resize => Convert to JPEG => Save to Disk.

    Golang HTTP Handler to Upload Image = Resize = Convert to JPEG = Save to Disk. : gistfile1.go
    Go
    func UploadHandler(w http.ResponseWriter, r *http.Request) {
    
    	file, _, err := r.FormFile("file")
    	if err != nil {
    		log.Println(err)
    		http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
    		return
    	}
    
    	img, _, err := image.Decode(file)
    	if err != nil {
    		log.Println(err)
    		http.Error(w, http.StatusText(http.StatusUnsupportedMediaType), http.StatusUnsupportedMediaType)
    		return
    	}
    
    	m := resize.Resize(1000, 0, img, resize.Lanczos3)
    
    	out, err := os.Create("test_resized.jpg")
    	if err != nil {
    		log.Println(err)
    		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
    		return
    	}
    	defer out.Close()
    
    	// Encode into jpeg http://blog.golang.org/go-image-package
    	err = jpeg.Encode(out, m, nil)
    	if err != nil {
    		log.Println(err)
    		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
    		return
    	}
    }
    
    

    public by mporru @ Amazon_AWS_PHP_API  2458  12  5  0

    Amazon AWS - PHP: Upload a file taken from an external site

    This snippet demonstrates how to upload a file to a S3 Bucket, taking it form a url. In order to use this service you must enable Amazon Simple Storage Service (Amazon S3) in your account. Taken from: http://www.sitepoint.com/getting-started-with-the-aws-php-sdk/
    <?php
    require_once 'sdk.class.php';
    $s3 = new AmazonS3();
    // Create Object is pretty self explanatory:
    // Arg 1: The bucket where your file will be created.
    // Arg 2: The name of your file.
    // Arg 3: An array of Options.
    //        In this case we're specifying the &quot;body&quot; option (opening a file from the web),
    //        we're setting the contentType of the file so browsers know its an image,
    //        and we're setting the ACL setting to allow this file to be read by anyone.
    $response=$s3->create_object('myBucketName', 'os_logo.png', array('body'=>file_get_contents('http://www.opensociety.it/wp-content/uploads/2012/12/header_OS.png'), 'content_type'=>'image/gif', 'acl'=>AmazonS3::ACL_PUBLIC));
    // Check if everything is okay.
    if ($response->isOK()) {
    	echo("File uploaded correctly");
    } else {
    	echo("There was an error uploading the file!");
    }
    ?>

    public by Aysad Kozanoglu  1646  24  3  0

    Cordova Camera Plugin cordova-plugin-camera upload jquery ajax to server request

    Cordova Camera Plugin cordova-plugin-camera upload jquery ajax to server request: cordova-plugin-camera-index.html
    <!DOCTYPE html>
    <!-- Aysad Kozanoglu -->
    <html>
      <head>
        <title>foto cek</title>
    	<style>
    	html {
    		-webkit-user-select: none;
    	}
    	</style>
    	<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0;" />
    	<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
        <script type="text/javascript" charset="utf-8" src="cordova.js"></script>
    
        <script type="text/javascript" charset="utf-8">
    
        var pictureSource;   // picture source
        var destinationType; // sets the format of returned value
    
        // Wait for device API libraries to load
        //
    		function onLoad() {
    			document.addEventListener("deviceready", onDeviceReady, false);
    		}
    
        // device APIs are available
        //
        function onDeviceReady() {
            pictureSource=navigator.camera.PictureSourceType;
            destinationType=navigator.camera.DestinationType;
    
        }
    
        // Called when a photo is successfully retrieved
        //
        function onPhotoDataSuccess(imageData) {
    		var smallImage = document.getElementById('smallImage');	
    	  
    		smallImage.style.display = 'block';
    		smallImage.src = "data:image/jpeg;base64," + imageData;
    		fotoUpload(imageData);
        }
    
        // A button will call this function
        //
        function capturePhotoEdit() {
          // Take picture using device camera, allow edit, and retrieve image as base64-encoded string
          navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 20, allowEdit: true,
            destinationType: destinationType.DATA_URL });
        }
    
    
        // Called if something bad happens.
        //
        function onFail(message) {
          alert('Failed because: ' + message);
        }
    
        </script>
      </head>
      <body onload="onLoad()">
    	<center>
    	<img src="logo.png" width="50%" border=0>
    	<br>
    	<h1>Entwicklungsumgebung</h1>
    	<br>
    	Kamera Photoschuss und upload Server
    	<br><br><br><br>
    	 <button onclick="capturePhotoEdit();" style="height:60px;width:80%">Photo Schnappschuss</button>
    	 <br><br><br>
    	 <a href="http://5.45.96.121/upload/" target ="_blank"> <h2>Bilder auf dem Server ansehen </h2></a>
    	 <br><br><br>
    	<div id="ajaxStatus"></div>
    	<img style="display:none;width:50%" id="smallImage" src="" />
    	<br><br><font size="-2"> Erfinder: Levent Yakar <br> Architekt: Aysad Kozanoglu
    
    	<script type="text/javascript" charset="utf-8">
          	$(document).ready(function(){
            $("#ajaxStatus").html("ein Bild aufnehmen");
          
          });	
          function fotoUpload(imageData){
          	//alert(imageData);
          	$.ajax({
          		type: "POST",
          		url: "http://5.45.96.121/upload/up2.php",
          		data: { img_data:imageData},
          		cache: false,
          		contentType: "application/x-www-form-urlencoded",
          		success: function (result) {
          			alert("upload OK: "+ result);
          		}
          	});		
          	$("#ajaxStatus").html("bild hochgeladen");
          }
    	</script>
      </body>
    </html>
    
    
    • Public Snippets
    • Channels Snippets