Support Generate Presigned URL for S3
This commit is contained in:
@@ -2104,6 +2104,56 @@ extern "C" ANSULT_API int UploadPrefixJpegImageANSAWSHandle(ANSCENTER::ANSAWSS3
|
||||
return -4;
|
||||
}
|
||||
}
|
||||
extern "C" ANSULT_API int GeneratePresignedURLANSAWSHandle(ANSCENTER::ANSAWSS3** Handle, const char* bucketName, const char* prefix, const char* objectName, int validDays, LStrHandle presignedURL) {
|
||||
ANS_DBG("ANSAWS", "GeneratePresignedURL called: HandlePtr=%p, *Handle=%p, bucket=%s, prefix=%s, object=%s, validDays=%d",
|
||||
(void*)Handle,
|
||||
Handle ? (void*)*Handle : nullptr,
|
||||
bucketName ? bucketName : "(null)",
|
||||
prefix ? prefix : "(null)",
|
||||
objectName ? objectName : "(null)",
|
||||
validDays);
|
||||
if (Handle == nullptr || *Handle == nullptr ||
|
||||
bucketName == nullptr || prefix == nullptr ||
|
||||
objectName == nullptr || presignedURL == nullptr)
|
||||
{
|
||||
ANS_DBG("ANSAWS", "GeneratePresignedURL: returning 0 (null/invalid arg)");
|
||||
return 0;
|
||||
}
|
||||
AWSHandleGuard guard(AcquireAWSHandle(*Handle));
|
||||
if (!guard) {
|
||||
ANS_DBG("ANSAWS", "GeneratePresignedURL: returning -1 (handle %p not in registry)", (void*)*Handle);
|
||||
return -1;
|
||||
}
|
||||
try {
|
||||
std::string outURL;
|
||||
if (guard.get()->GeneratePresignedURL(bucketName, prefix, objectName, validDays, outURL)) {
|
||||
int size = (int)outURL.length();
|
||||
MgErr error = DSSetHandleSize(presignedURL, sizeof(int32) + size * sizeof(uChar));
|
||||
if (error == noErr) {
|
||||
(*presignedURL)->cnt = size;
|
||||
memcpy((*presignedURL)->str, outURL.c_str(), size);
|
||||
}
|
||||
ANS_DBG("ANSAWS", "GeneratePresignedURL OK (1): object=%s -> %s",
|
||||
objectName ? objectName : "(null)", outURL.c_str());
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
ANS_DBG("ANSAWS", "GeneratePresignedURL FAILED (-2): object=%s",
|
||||
objectName ? objectName : "(null)");
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
catch (std::exception& e) {
|
||||
ANS_DBG("ANSAWS", "GeneratePresignedURL EXCEPTION (-3): object=%s, what=%s",
|
||||
objectName ? objectName : "(null)", e.what());
|
||||
return -3;
|
||||
}
|
||||
catch (...) {
|
||||
ANS_DBG("ANSAWS", "GeneratePresignedURL EXCEPTION (-4): object=%s, unknown exception",
|
||||
objectName ? objectName : "(null)");
|
||||
return -4;
|
||||
}
|
||||
}
|
||||
extern "C" ANSULT_API int UploadPrefixMultiPartDataANSAWSHandle(ANSCENTER::ANSAWSS3** Handle, const char* bucketName, const char* prefix, const char* fileDataPath, const char* objectName, int fileSize, LStrHandle uploadedFilePath) {
|
||||
if (Handle == nullptr || *Handle == nullptr || bucketName == nullptr || prefix == nullptr || fileDataPath == nullptr || fileSize <= 0 ) {
|
||||
return 0;
|
||||
@@ -2221,6 +2271,14 @@ extern "C" ANSULT_API int UploadPrefixJpegImageANSAWSHandle_CPP(ANSCENTER::ANSAW
|
||||
return guard.get()->UploadPrefixJpegImage(bucketName, prefix, jpeg_string, bufferLength, fileName, uploadedFilePath) ? 1 : 0;
|
||||
} catch (...) { return 0; }
|
||||
}
|
||||
extern "C" ANSULT_API int GeneratePresignedURLANSAWSHandle_CPP(ANSCENTER::ANSAWSS3** Handle, const char* bucketName, const char* prefix, const char* objectName, int validDays, std::string& presignedURL) {
|
||||
if (Handle == nullptr || *Handle == nullptr || bucketName == nullptr || prefix == nullptr || objectName == nullptr) return 0;
|
||||
AWSHandleGuard guard(AcquireAWSHandle(*Handle));
|
||||
if (!guard) return 0;
|
||||
try {
|
||||
return guard.get()->GeneratePresignedURL(bucketName, prefix, objectName, validDays, presignedURL) ? 1 : 0;
|
||||
} catch (...) { return 0; }
|
||||
}
|
||||
|
||||
// ════════════════════════════════════════════════════════════════════════════
|
||||
// V2 API — handle-by-value for LabVIEW (uint64_t instead of Handle**)
|
||||
@@ -2837,6 +2895,28 @@ extern "C" ANSULT_API int UploadPrefixJpegImageANSAWSHandle_V2(uint64_t handleVa
|
||||
catch (...) { return 0; }
|
||||
}
|
||||
|
||||
extern "C" ANSULT_API int GeneratePresignedURLANSAWSHandle_V2(uint64_t handleVal, const char* bucketName, const char* prefix, const char* objectName, int validDays, LStrHandle presignedURL) {
|
||||
auto* _v2h = reinterpret_cast<ANSCENTER::ANSAWSS3*>(handleVal); if (!_v2h) return 0;
|
||||
if (bucketName == nullptr || prefix == nullptr || objectName == nullptr || presignedURL == nullptr) return 0;
|
||||
AWSHandleGuard guard(AcquireAWSHandle(_v2h));
|
||||
if (!guard) return 0;
|
||||
try {
|
||||
std::string outURL;
|
||||
if (guard.get()->GeneratePresignedURL(bucketName, prefix, objectName, validDays, outURL)) {
|
||||
int size = (int)outURL.length();
|
||||
MgErr error = DSSetHandleSize(presignedURL, sizeof(int32) + size * sizeof(uChar));
|
||||
if (error == noErr) {
|
||||
(*presignedURL)->cnt = size;
|
||||
memcpy((*presignedURL)->str, outURL.c_str(), size);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
else return 0;
|
||||
}
|
||||
catch (std::exception& e) { return 0; }
|
||||
catch (...) { return 0; }
|
||||
}
|
||||
|
||||
extern "C" ANSULT_API int UploadPrefixMultiPartDataANSAWSHandle_V2(uint64_t handleVal, const char* bucketName, const char* prefix, const char* fileDataPath, const char* objectName, int fileSize, LStrHandle uploadedFilePath) {
|
||||
auto* _v2h = reinterpret_cast<ANSCENTER::ANSAWSS3*>(handleVal); if (!_v2h) return 0;
|
||||
if (bucketName == nullptr || prefix == nullptr || fileDataPath == nullptr || fileSize <= 0 || uploadedFilePath == nullptr) return 0;
|
||||
|
||||
Reference in New Issue
Block a user