Coder Social home page Coder Social logo

baozoumanhua / qiniu_direct_uploader Goto Github PK

View Code? Open in Web Editor NEW

This project forked from huobazi/qiniu_direct_uploader

0.0 17.0 0.0 113 KB

A gem can direct upload your files to a Qiniu storage bucket

Home Page: https://rubygems.org/gems/qiniu_direct_uploader

License: MIT License

Ruby 46.00% CoffeeScript 49.75% CSS 4.25%

qiniu_direct_uploader's Introduction

Qiniu Direct Uploader

This Gem can direct upload your files to a Qiniu storage bucket.

Installation

Add this line to your application's Gemfile:

gem 'qiniu_direct_uploader'

And then execute:

$ bundle

Or install it yourself as:

$ gem install qiniu_direct_uploader

Usage

see the example project: https://github.com/huobazi/qiniu-direct-upload-example

Views

<%= qiniu_uploader_form callback_url: items_path,
  bucket:        'spec-test',
  id:            "photograph-uploader",
  key:           "items/#{Date.today.strftime('%Y/%m')}/{timestamp}-{unique-id}-#{SecureRandom.hex}-{filename}",
  custom_fields: {aaa:1,bbb:2},
  progress_bar_id: 'progress-bar',
  drop_paste_zone_id: 'dropzone' do %>

  <div class="bars" id="progress-bar">
    <%= file_field_tag :file, multiple: true, accept: "image/gif, image/jpeg" %> You can also drag and drop files here
  </div>
<% end %>

Javascript

$(document).ready ->
  photoForm = $("form#photograph-uploader")
  if photoForm.length > 0
    photoForm.QiniuUploader
      # see also  https://github.com/blueimp/jQuery-File-Upload/wiki/Options
      autoUpload: true
      singleFileUploads: false
      limitMultiFileUploads: 2
      customCallbackData: {"xyz": 100}
      onFilesAdd: (file) ->
        if file.type != "image/jpeg"
          alert('please select image')
          return false
        else
          return true

    photoForm.bind "ajax:success", (e, data) ->
      console.log('success')
      console.log(data)

    photoForm.bind "ajax:failure", (e, data) ->
      console.log('failure')
      console.log(data)

see also:

  1. http://docs.qiniu.com/api/v6/put.html#upload-without-callback
  2. http://docs.qiniu.com/api/v6/put.html#upload-api
  3. http://docs.qiniu.com/api/v6/put.html#uploadToken-returnBody

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

qiniu_direct_uploader's People

Contributors

huobazi avatar iamzhangdabei avatar

Watchers

代码之力 avatar Tim avatar Liu Yuyu avatar Michael Ding avatar  avatar James Cloos avatar Ethan Yu avatar andrewzhyl avatar Han avatar Ke Pan avatar John Tai avatar Onet away avatar Hging avatar Remer avatar David Hu avatar  avatar Alex Xu avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.