Skip to content

Commit

Permalink
headobject,deleteobject函数
Browse files Browse the repository at this point in the history
  • Loading branch information
Dipper209 committed Jul 9, 2024
1 parent b9e48ce commit 1bd8bc9
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 9 deletions.
44 changes: 36 additions & 8 deletions cosclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,19 +144,47 @@ bool COSClient::save2Local(const QString &path, const QString &localpath, const
return true;
}

QMap<QString,QString> COSClient::headObject(const QString &path, const QString &localpath, const QString &versionId)
preResponse COSClient::headObject(const QString &path, const QString &localpath,const QString &versionId, headHeader &reqHeader)
{
preRequest request;
if(!versionId.isEmpty())
{
if(!versionId.isEmpty()) {
request.customHeaders.insert("versionId", versionId);
}
request.customHeaders.insert("If-Modified-Since", "");
request.customHeaders.insert("If-Unmodified-Since", "");
request.customHeaders.insert("If-Match", "");
request.customHeaders.insert("If-None-Match", "");
if(!reqHeader.ifModifiedSince.isEmpty()) {
request.customHeaders.insert("If-Modified-Since", reqHeader.ifModifiedSince);
}
if(!reqHeader.ifUnmodifiedSince.isEmpty()) {
request.customHeaders.insert("If-Unmodified-Since", reqHeader.ifUnmodifiedSince);
}
if(!reqHeader.ifMatch.isEmpty()) {
request.customHeaders.insert("If-Match", reqHeader.ifMatch);
}
if(!reqHeader.ifNoneMatch.isEmpty()) {
request.customHeaders.insert("If-None-Match", reqHeader.ifNoneMatch);
}
preResponse response = invokeHeadRequest(path, request);
return response.getMetaDatas();
return response;
}

bool COSClient::deleteObject(const QString &path, const QString &versionId)
{
preRequest request;
bool haveId=!versionId.isEmpty();
if(haveId) {
request.customHeaders.insert("versionId", versionId);
}
preResponse response = invokeDeleteRequest(path,request);
// 获取 x-cos-version-id 响应头
QString responseVersionId = response.headers.value("x-cos-version-id");
// 获取 x-cos-delete-marker 响应头
bool deleteMarker = response.headers.value("x-cos-delete-marker")=="true"?"true":"false";
if(haveId&&deleteMarker){
qDebug()<<"标记"<<responseVersionId<<"为删除";
}
else if(!haveId && deleteMarker){
qDebug()<<"创建了一个删除标记作为"<<path<<"的最新版本";
}
return deleteMarker;
}

QString COSClient::multiUpload(const QString &path, const QString &localpath, QMap<QString, QString> metaDatas)
Expand Down
9 changes: 8 additions & 1 deletion cosclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
#include <QtNetwork/QNetworkReply>
#include <QUrl>
#include <QDomDocument>
struct headHeader {
QString ifModifiedSince; // If-Modified-Since 请求头
QString ifUnmodifiedSince; // If-Unmodified-Since 请求头
QString ifMatch; // If-Match 请求头
QString ifNoneMatch; // If-None-Match 请求头
};
struct preRequest{
QMap<QString, QString> queryParams;
QByteArray data;
Expand Down Expand Up @@ -64,7 +70,8 @@ class COSClient : public QObject
QString completeMultipartUpload(QString path, QString uploadId, QMap<int, QString> partEtagMap);
QByteArray getObject(const QString &path,const QString &versionId, QMap<QString,QString> &respHeaders);
bool save2Local(const QString &path, const QString &localpath,const QString &versionId, QMap<QString,QString> &respMetaDatas);
QMap<QString,QString> headObject(const QString &path, const QString &localpath, const QString &versionId);
preResponse headObject(const QString &path, const QString &localpath,const QString &versionId, headHeader &reqHeader);
bool deleteObject(const QString &path, const QString &versionId);
QString multiUpload(const QString &path, const QString &localpath, QMap<QString,QString> metaDatas=QMap<QString,QString>());

private:
Expand Down

0 comments on commit 1bd8bc9

Please sign in to comment.