<commit_before># 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
```erb
<%= qiniu_uploader_form callback_url: items_path,
  bucket:        'spec-test',
  id:            "photograph-uploader",
  save_key:       "uploads/items/$(year)/$(mon)/$(day)/$(etag)/$(fname)",
  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
```coffee
$(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
<commit_msg>add a link for save_key<commit_after># 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
```erb
<%= qiniu_uploader_form callback_url: items_path,
  bucket:        'spec-test',
  id:            "photograph-uploader",
  save_key:       "uploads/items/$(year)/$(mon)/$(day)/$(etag)/$(fname)",
  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 %>
```

see the save_key settings: http://developer.qiniu.com/docs/v6/api/overview/up/response/vars.html#magicvar

### Javascript
```coffee
$(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

{'fraction_non_alphanumeric': 0.13896780303030304, 'fraction_numerical': 0.008759469696969696, 'mean_word_length': 3.276315789473684, 'pattern_counts': {'":': 2, '<': 13, '<?xml version=': 0, '>': 23, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3413062', 'n_tokens_mistral': 1489, 'n_tokens_neox': 1405, 'n_words': 355}