Skip to main content

Callback

Struct Callback 

Source
pub struct Callback {
    pub url: String,
    pub host: Option<String>,
    pub body: String,
    pub sni: Option<bool>,
    pub body_type: Option<CallbackBodyType>,
    pub custom_variables: HashMap<String, String>,
}
Expand description

The callback while call

  • put_object_from_file
  • put_object_from_buffer
  • put_object_from_base64
  • complete_multipart_upload

to create an object, if create object successfully, the OSS server will call your server according to this callback config with POST request method.

Official document: https://help.aliyun.com/zh/oss/developer-reference/callback

Fields§

§url: String

创建 Object 成功之后,OSS 服务器会 POST 到这个 URL。 该 URL 调用后的要求有:

  • 响应 HTTP/1.1 200 OK
  • 响应头 Content-Length 必须是合法的值
  • 响应体为 JSON 格式
  • 响应体最大为 3MB

另外:

  • 支持同时配置最多 5 个 URL,多个 URL 间以分号(;)分隔。OSS 会依次发送请求,直到第一个回调请求成功返回。
  • 支持 HTTPS 协议地址。
  • 不支持填写 IPV6 地址,也不支持填写指向 IPV6 地址的域名。
  • 为了保证正确处理中文等情况,此 URL 需做编码处理, 例如 https://example.com/中文.php?key=value&中文名称=中文值 需要编码为 https://example.com/%E4%B8%AD%E6%96%87.php?key=value&%E4%B8%AD%E6%96%87%E5%90%8D%E7%A7%B0=%E4%B8%AD%E6%96%87%E5%80%BC
§host: Option<String>

发起回调请求时 Host 头的值,格式为域名或 IP 地址。仅在设置了 url 时有效。 如果没有配置 host,则解析 url 中的 URL,并将解析的 Host 填充到 Host 请求头中。

§body: String

发起回调时请求Body的值,例如 key=${object}&etag=${etag}&my_var=${x:my_var}

支持:

  • OSS系统参数,要写成 ${var_name} 格式
    • bucket: The bucket name
    • object: The object key
    • etag: The ETag of the object
    • size: 以字节为单位的 Object 大小。调用 complete_multipart_upload 时,size 为整个 Object 的大小
    • mimeType: 资源类型,例如 jpeg 图片的资源类型为 image/jpeg
    • imageInfo.height: 图片高度。该变量仅适用于图片格式,对于非图片格式,该变量的值为空
    • imageInfo.width: 图片宽度。该变量仅适用于图片格式,对于非图片格式,该变量的值为空
    • imageInfo.format: 图片格式,例如 JPG、PNG 等。该变量仅适用于图片格式,对于非图片格式,该变量的值为空
    • crc64: 与上传文件后返回的 x-oss-hash-crc64ecma 头内容一致
    • contentMd5: 与上传文件后返回的 Content-MD5 头内容一致。仅在 put_object_from_xxx 时候该变量的值不为空
    • vpcId: 发起请求的客户端所在的 VpcId。如果不是通过 VPC 发起请求,则该变量的值为空
    • clientIp: 发起请求的客户端 IP 地址
    • reqId: 发起请求的 RequestId
    • 发起请求的接口名称,例如 PutObjectPostObject
  • 自定义参数,其使用格式为 ${x:var_name}。参数值放到 custom_variables
  • 常量(字面量)
§sni: Option<bool>

客户端发起回调请求时,OSS是否向地址发送服务器名称指示 SNI(Server Name Indication)。 是否发送 SNI 取决于服务器的配置和需求。 对于使用同一个 IP 地址来托管多个 TLS/SSL 证书的服务器的情况,建议选择发送 SNI

§body_type: Option<CallbackBodyType>

发起回调请求时候的 Content-Type。默认是:application/x-www-form-urlencoded

§custom_variables: HashMap<String, String>

在回调请求体 (body) 中携带的数据,如果有自定义参数,请使用此属性容纳自定义参数的值。 Key 为自定义变量名,但是不包含 x: 前缀。在生成 body 的时候会自动增加 注意:这里我使用了 Map 来接受自定义参数,也就是说,这里不支持多个同名的自定义参数来表示集合数据类型

Trait Implementations§

Source§

impl Clone for Callback

Source§

fn clone(&self) -> Callback

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Callback

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Callback

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Callback

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,