Skip to content

Commit

Permalink
feat: gcs multipart upload support cache control
Browse files Browse the repository at this point in the history
  • Loading branch information
fatelei committed Aug 29, 2023
1 parent 3a76ec2 commit 0d6747d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
6 changes: 3 additions & 3 deletions core/src/services/gcs/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,9 @@ impl Accessor for GcsBackend {
}

async fn create_dir(&self, path: &str, _: OpCreateDir) -> Result<RpCreateDir> {
let mut req = self
.core
.gcs_insert_object_request(path, Some(0), None, AsyncBody::Empty)?;
let mut req =
self.core
.gcs_insert_object_request(path, Some(0), None, None, AsyncBody::Empty)?;

self.core.sign(&mut req).await?;

Expand Down
14 changes: 13 additions & 1 deletion core/src/services/gcs/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// specific language governing permissions and limitations
// under the License.

use std::collections::HashMap;
use std::fmt::Debug;
use std::fmt::Formatter;
use std::fmt::Write;
Expand Down Expand Up @@ -209,6 +210,7 @@ impl GcsCore {
path: &str,
size: Option<u64>,
content_type: Option<&str>,
cache_control: Option<&str>,
body: AsyncBody,
) -> Result<Request<AsyncBody>> {
let p = build_abs_path(&self.root, path);
Expand Down Expand Up @@ -236,13 +238,23 @@ impl GcsCore {
if let Some(storage_class) = &self.default_storage_class {
let mut multipart = Multipart::new();

let mut meta_data = HashMap::new();
meta_data.insert("storageClass".to_string(), storage_class.to_string());
meta_data.insert(
"cacheControl".to_string(),
cache_control
.unwrap_or("public, max-age=3600")
.parse()
.unwrap(),
);

multipart = multipart.part(
FormDataPart::new("metadata")
.header(
CONTENT_TYPE,
"application/json; charset=UTF-8".parse().unwrap(),
)
.content(json!({"storageClass": storage_class}).to_string()),
.content(json!(meta_data).to_string()),
);

let mut media_part = FormDataPart::new("media").header(
Expand Down
1 change: 1 addition & 0 deletions core/src/services/gcs/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ impl GcsWriter {
&percent_encode_path(&self.path),
Some(size),
self.op.content_type(),
self.op.cache_control(),
body,
)?;

Expand Down

0 comments on commit 0d6747d

Please sign in to comment.