Giter VIP home page Giter VIP logo

Comments (6)

dead-horse avatar dead-horse commented on May 9, 2024 1

可以加一个 exist 接口,404 不报错返回 null,还是保留 head 现在这样吧,不然这种不兼容变更不好发

from ali-oss.

rockuw avatar rockuw commented on May 9, 2024

增加exist方法的话其实会多一次请求:

if (client.object_exist(obj)) { // 1st req
  var r = client.head(obj);  // 2nd req
}

似乎是.head返回null更好一些。@dead-horse 怎么看?

from ali-oss.

4tj avatar 4tj commented on May 9, 2024

@rockuw
最初设计时,对于想判断 object 是否存在是怎么考虑的?

有个问题,看 head 的方法是发一个请求,通过判断 statusCode。但是这样后台会增加失败访问的计数器,不利于统计。你怎么看?

from ali-oss.

rockuw avatar rockuw commented on May 9, 2024

@qinshou

OSS的API里没有相关的exist的API,怎么处理完全取决于用户。
实际上,因为下面的操作不是原子的,提供这样一个API的意义也不大,而且还会增加一次网络请求:

if (client.object_exist(obj)) { // 1st req
  var r = client.head(obj);  // 2nd req
}

from ali-oss.

4tj avatar 4tj commented on May 9, 2024

@rockuw
实际上的用途是

if(!client.head(obj)) { // 不存在
  client.put(obj);
}

我这里场景是上传队列,要做个去重

from ali-oss.

rockuw avatar rockuw commented on May 9, 2024

@qinshou

你自己封装一个函数好了:

function objectExist(client, obj) {
  // xxx  
}

from ali-oss.

Related Issues (20)

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.