SimditorAliyunRails
Using the Aliyun OSS JavaScript SDK to upload pictures on the basis of Simditor-Rails.
Installation
Add this line to your application's Gemfile:
gem 'simditor_aliyun_rails'
And then execute:
$ bundle
Or install it yourself as:
$ gem install simditor_aliyun_rails
Usage
in application.js
//= require simditor
in application.css
*= require simditor
Initialization
var editor = new Simditor({
textarea: $('#question_content'),
upload: {
url: '',
params: {
// main account or sub account accessKeyId accessKeySecret
accessKeyId: 'LTAI8vWypOgeFVqA',
accessKeySecret: 'ghiXS9HQnosR9f9Bw191C7DloNEaDp',
bucket: 'example',
region: 'oss-cn-beijing',
// sts accessKeyId accessKeySecret
// region: 'oss-cn-beijing',
// accessKeyId: 'STS.EHaAs5yC5RtBc7BAEDNLyznui',
// accessKeySecret: 'HJ6nUeLF71PCv9hpUgM5RkZpzYbtDoq3WqrcX4XMV6YY',
// stsToken: 'CAIS9QF1q6Ft5B2CfSjIpIvUIcmBlJwU5bapYRHzpUURQsNVlaveizz2IH9JfnBqCegas/QwmGFR7fcTlq9uUIUdHRWcxTOEK38To22beIPkl5Gfz95t0e+IewW6Dxr8w7WhAYHQR8/cffGAck3NkjQJr5LxaTSlWS7OU/TL8+kFCO4aRQ6ldzFLKc5LLw950q8gOGDWKOymP2yB4AOSLjIx51cg1D4itvTgn5TAtkeGtjCglL9J/baWC4O/csxhMK14V9qIx+FsfsLDqnUPtkITrvcu0PEUpmuW54rMUkMp4gWbPuOR6sdoIEpmfKkmFr7+YG5fPi7x0BqAAXKfsK6VgPxxOzF2VZtxlS4clBhR5+LY3RbWlH5we4BNVpuHACb4AqgfLNCnQnrbec7Dh4BDZPmJixhXubiI9+Dptp43eMZigbUxrj8BOR1RtLwUPRmYh3cvDfPcEkLV+yZRLsxKIscg6qMZyQr2dUL42hHNuUDhqw0ZxUartu9T',
// bucket: 'example',
// image prefix
image_prefix_url: '//prod.example.com/',
image_prefix_folder: 'questions/',
},
fileKey: 'upload_file',
connectionCount: 3,
leaveConfirm: 'Uploading is in progress, are you sure to leave this page?'
}
//optional options
});
The params will be passed to the Aliyun OSS JavaScript SDK, and the other configuration is the same as the official version, please check herehttp://simditor.tower.im/
The final picture url is image_prefix_url+image_prefix_folder+fileName,example:
//prod.example.com/questions/a.jpg
image_prefix_url is mainly used for OSS custom domain names, and if the OSS address is not filled in, image_prefix_folder is mainly used to divide the picture catalog according to the business.
Aliyun OSS JavaScript SDk is herehttps://github.com/ali-sdk/ali-oss?spm=5176.doc32068.2.4.4u5zfu
Risk
//TODO upload failed handle
Because SDK uploaded pictures through XHR. Now it has been replaced by Aliyun OSS SDK. It doesn't know how to deal with error handling. Friends who know it trouble us to deal with it. Thank you very much!
In vendor/assets/javascripts/simditor/uploader.js line 155.
Development
After checking out the repo, run bin/setup
to install dependencies. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/ixuea/simditor_aliyun_rails.