Giter Club home page Giter Club logo

qiniu's Introduction

Qiniu

Build Status Coverage Status Inline docs hex.pm version

Qiniu sdk for Elixir

Installation and config

  • Add qiniu as dependence and application
# mix.exs
def application do
  [applications: [:qiniu]]
end

defp deps do
  [{:qiniu, "~> 0.3.0"}]
end

Then run $ mix deps.get

  • Config the Qiniu API keys
# config/prod.secret.exs (You'd better not add this file to git)
config :qiniu, Qiniu,
  access_key: "key",
  secret_key: "secret"

Usage

Upload

Get the token for uploading

policy = Qiniu.PutPolicy.build("scope")
uptoken = Qiniu.Auth.generate_uptoken(policy)

Upload a local file in server

put_policy = Qiniu.PutPolicy.build("books")
Qiniu.Uploader.upload put_policy, "~/cool.jpg", key: "cool.jpg"

Chunked upload

put_policy = Qiniu.PutPolicy.build("books")
Qiniu.ChunkUpload.chunk_upload put_policy, "~/cool.jpg", key: "cool.jpg"

Download

Get the authorized download url

Qiniu.Auth.authorize_download_url(url, 3600)

Media Processing

AV transcoding

Qiniu.Fop.AV.trans_fops([avthumb: "mp4", s: "640x360", saveas: "bucket1:test.mp4"])

See the doc for other features

TODO

There're many small features, implements of which are bothering. And some of them seem not very useful. So I don't plan to implement all of them until I find some useful. You can create issues when you need some features or just implement them by yourself.

  • Uploading
    • 直传文件(upload)
    • 创建块(mkblk)
    • 上传片(bput)
    • 创建文件(bput)
  • Resource management
    • 获取资源信息(stat)
    • 复制资源(copy)
    • 移动资源(move)
    • 删除资源(delete)
    • 批量操作(batch)
    • 列举资源(list)
    • 抓取资源(fetch)
    • 更新镜像资源(prefetch)
    • 修改元信息(chgm)
  • Data handling
    • Image
      • 图片基本信息(info)
      • 图片EXIF信息(exif)
      • 水印(watermark)
      • 图片主色调(avg_hue)
    • 资源下载二维码(qrcode)

qiniu's People

Contributors

beams0305 avatar feixionglee avatar hxgdzyuyi avatar lcpmarvel avatar lowks avatar tony612 avatar xingxing avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

qiniu's Issues

Prefetch returnes `:timeout`

When I prefetch a resource, it throws a :timeout exception, but the resource is actually prefetched by Qiniu.

** (HTTPoison.Error) :timeout
    (httpoison) lib/httpoison.ex:66: HTTPoison.request!/5
    (qiniu) lib/qiniu/http.ex:24: Qiniu.HTTP.request/4
    (elixir) lib/enum.ex:651: Enum."-each/2-lists^foreach/1-0-"/2
    (elixir) lib/enum.ex:651: Enum.each/2
    (stdlib) erl_eval.erl:670: :erl_eval.do_apply/6
    (elixir) lib/code.ex:168: Code.eval_string/3

The implementation:

defmodule HMQ do
  @bucket "hex-mirror"
  @keys ~w(
    registry.ets.gz
    registry.ets.gz.signed
  )

  def prefetch_all do
    @keys
    |> Enum.each(&prefetch/1)
  end

  def prefetch(key) do
    Qiniu.Resource.prefetch("hex-mirror:" <> key)
  end
end

online doc

doc ":" in resource.ex appears to be ":" in online doc

old httpoison dep warning

I get when I run mix deps.get after mix deps.clean --all

hackney 1.6.6 RETIRED!
(invalid)

and when I run mix deps.tree

├── qiniu ~> 0.3.5 (Hex package)
│ ├── httpoison ~> 0.10.0 (Hex package)
│ │ └── hackney ~> 1.6.3 (Hex package)

I think upgrade of httpoison is required to fix this warning.

delete resource error

[error] #PID<0.722.0> running DoScience.Web.Endpoint terminated
Server: localhost:4000 (http)
Request: POST /api/editor/delete_image
** (exit) an exception was raised:
** (Poison.SyntaxError) Unexpected end of input at position 0
(poison) lib/poison/parser.ex:55: Poison.Parser.parse!/2
(poison) lib/poison.ex:83: Poison.decode!/2
(qiniu) lib/qiniu/http.ex:34: Qiniu.HTTP.request/4
(do_science) lib/do_science/web/controllers/editor_controller.ex:120: DoScience.Web.EditorController.delete_image/2
(do_science) lib/do_science/web/controllers/editor_controller.ex:1: DoScience.Web.EditorController.action/2
(do_science) lib/do_science/web/controllers/editor_controller.ex:1: DoScience.Web.EditorController.phoenix_controller_pipeline/2
(do_science) lib/do_science/web/endpoint.ex:1: DoScience.Web.Endpoint.instrument/4
(phoenix) lib/phoenix/router.ex:277: Phoenix.Router.call/1
(do_science) lib/do_science/web/endpoint.ex:1: DoScience.Web.Endpoint.plug_builder_call/2
(do_science) lib/plug/debugger.ex:123: DoScience.Web.Endpoint."call (overridable 3)"/2
(do_science) lib/do_science/web/endpoint.ex:1: DoScience.Web.Endpoint.call/2
(plug) lib/plug/adapters/cowboy/handler.ex:15: Plug.Adapters.Cowboy.Handler.upgrade/4
(cowboy) /home/cjen/Documents/do_science/deps/cowboy/src/cowboy_protocol.erl:442: :cowboy_protocol.execute/4

and the response in request in Qiniu.HTTP is

[debug] %HTTPoison.Response{body: "", headers: [{"Server", "openresty"}, {"Date", "Tue, 18 Apr 2017 09:40:53 GMT"}, {"Content-Type", "application/json"}, {"Content-Length", "0"}, {"Connection", "close"}, {"X-Log", "RA:101.71.81.88:80;rs9_3.sel:3;rs9_3.sel;rs9_3.ups;rwro.rm:4;MQ;mc.d;RS:7;ZONEPROXY:44;NUPROXY:64"}, {"X-Reqid", "YEEAAJN4Cd2HdLYU"}, {"X-Reqid", "YEEAAJN4Cd2HdLYU"}, {"X-Reqid", "YEEAAJN4Cd2HdLYU"}], status_code: 200}

Set return_body in put_policy has no effect

put_policy = Qiniu.PutPolicy.build(@bucket, 
  return_body: ~s({"taked_at": ${avinfo.video.tags.creation_time}}))
IO.inspect Qiniu.Uploader.upload put_policy, file_path, key: "cool.mp4"

body: "{\"hash\":\"FpmaDb02KhRHGvaB9-MMKFWyqbwz\",\"key\":\"cool.mp4\"}"

body expected: "{\"taked_at\": \"2016-07-21 09:53:21\"}"

I read the document and found that the option keys in put_policy is not identical to the official document: http://developer.qiniu.com/article/developer/security/put-policy.html

Problem solved after modifying return_body to returnBody.

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.