- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在使用 SAS(共享访问签名)从 C++ 写入 Azure block Blob 时遇到问题。我正在使用 Blob REST API 和 Poco。 HTTP请求返回错误404(资源不存在),但我不知道我做错了什么。
我在服务器上用 C# 生成 SAS,如下所示(似乎工作正常):
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference("my-blob");
container.CreateIfNotExists();
SharedAccessBlobPolicy sasConstraints = new SharedAccessBlobPolicy();
sasConstraints.SharedAccessExpiryTime = DateTime.UtcNow.AddMinutes(40);
sasConstraints.Permissions = SharedAccessBlobPermissions.Write | SharedAccessBlobPermissions.List;
string sasContainerToken = container.GetSharedAccessSignature(sasConstraints);
return Request.CreateResponse(HttpStatusCode.OK, container.Uri + sasContainerToken);
在 Azure 门户中,我确实可以看到 Blob 容器正在按预期创建。我使用 HTTP 请求以 C++ 形式接收此 SAS。我得到的看起来像这样(出于安全原因替换了一些名称和签名):
然后我尝试使用 Poco 和 Blob REST API 创建文件。看起来像这样:
std::string cloudUrl = sasURI + "&restype=container";
std::string fileName = "fname.ext";
Poco::URI* uri = new Poco::URI(cloudUrl.c_str());
std::string* path = new std::string(uri->getPathAndQuery());
Poco::Net::HTTPSClientSession* session = new Poco::Net::HTTPSClientSession(uri->getHost(), uri->getPort());
std::string method = Poco::Net::HTTPRequest::HTTP_PUT;
Poco::Net::HTTPRequest* request = new Poco::Net::HTTPRequest(method, *path, Poco::Net::HTTPMessage::HTTP_1_1);
request->add("x-ms-blob-content-disposition", "attachment; filename=\"" + fileName + "\"");
request->add("x-ms-blob-type", "BlockBlob");
request->add("x-ms-meta-m1", "v1");
request->add("x-ms-meta-m2", "v2");
Poco::Net::HTTPResponse* httpResponse = new Poco::Net::HTTPResponse();
int fileContent = 42;
request->setContentLength(sizeof(int));
request->setKeepAlive(true);
std::ostream& outputStream = session->sendRequest(*request);
outputStream << fileContent;
std::istream &is = session->receiveResponse(*httpResponse);
Poco::Net::HTTPResponse::HTTPStatus status = httpResponse->getStatus();
std::ostringstream outString;
Poco::StreamCopier::copyStream(is, outString);
if (status != Poco::Net::HTTPResponse::HTTP_OK)
{
Logger::log("Connection failed\nstatus:", status, "\nreason:", httpResponse->getReason(), "\nreasonForStatus:", httpResponse->getReasonForStatus(status), "\nresponseContent:", outString.str());
}
我查过here REST API 的工作原理。我发现here使用 SAS 时,我不需要进行常规身份验证。
我在这里做错了什么?为什么我会收到 404 错误?
最佳答案
我终于弄清楚这里出了什么问题。 :)
上面的代码有两个问题。首先,文件名需要插入到 URL 中,正如 Gaurav Mantri 所解释的那样。这可以解决问题:
int indexOfQuestionMark = cloudUrl.find('?');
cloudUrl = cloudUrl.substr(0, indexOfQuestionMark) + "/" + fileName + cloudUrl.substr(indexOfQuestionMark);
另一个问题是我没有上传足够的字节。 sizeof(int)
是 4 个字节,而将 42 插入流中会将其转换为字符,使其只有 2 个字节。然后服务器继续等待剩余的 2 个字节。这使得这是上面示例代码中的正确行:
request->setContentLength(2);
此外,它无需这三行即可工作,因此我认为不需要它们:
request->add("x-ms-blob-content-disposition", "attachment; filename=\"" + fileName + "\"");
request->add("x-ms-meta-m1", "v1");
request->add("x-ms-meta-m2", "v2");
同样,似乎不需要添加此内容:"&restype=container"
。
最后,不需要编写 SharedAccessBlobPermissions.List
权限,因此可以在服务器端的 SAS 生成中忽略这些权限。
关于rest - 使用 SAS 和 REST 上传到 Azure Blob,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37678058/
有没有办法从 .sas 文件中打开 SAS 数据集进行查看(即在“ViewTable”窗口中)? 最佳答案 我认为这会做你想做的: dm log "vt sashelp.air"; 只需更改 "sas
如何在 SAS 程序中将 sas 数据表 (sas7bdat) 设置为只读? — 即使在 session 之间,该表也必须保持只读状态,尤其是当另一个用户注册该库并尝试写入数据集时。一旦创建了这些表,
如何将 mmddyy 变量转换为 date9 变量?例如,假设我们有以下内容: x = 05/10/2011 我希望 x 的形式为 10May2011。所以我做了以下事情: xnew =
我正在使用以下代码将文本文件导入 SAS: proc import datafile="C:\Users\Desktop\data.txt" out=Indivs dbms=dlm replace;
您好,我有兴趣为我在 SAS 中生成的数据制作一些稍微复杂的自定义格式。我需要它是数字类型。 格式 1 0="-" >0="%" %" 即 0 >>>>>>> - .74 >>>>> 74% -.65
我正在尝试弄清楚如何读取文本文件 (300mb) 中以逗号分隔但数据位于一行中的数据。 数据看起来像这样: a,b,c,d,e,f,g,h,i,j,k,l,m,false,false,true,1,3
我想将 SAS 数据集从 SAS 导出到 FTP。我可以使用以下命令导出 csv 文件(或 txt 文件): %macro export_to_ftp(dsn= ,outfile_name= ); F
这个问题在 SAS forum 上讨论过,与会者最终同意不同意。 问题很简单:SAS 在编译时为所有变量分配一个缺失值UNLESS一个变量出现在sum 语句中(在这种情况下,SAS 在编译时分配了一个
众所周知,SAS需要特别注意句子中的引号。 例如 %let quoted="I'd like to"; data temp; set temp; quoted=""ed"; r
我对 SAS 完全陌生,我很绝望。 所以,我的代码是: DATA abc; INPUT AA BB CC DD EE; CARDS; ; RUN; PROC PRINT DATA = abc; T
我在使用如下所示的数据集时遇到问题。它是不同位置/周的库存计数: data have; input itm location $ week inv; cards; 3 x 1 30 3 x 2
我们需要确定我们现在使用的是什么类型的 SAS(pc SAS 或服务器 SAS)。有什么方法可以找出我们使用的是什么 SAS,是指 PC SAS 还是 SAS Server? 最佳答案 使用“proc
假设我有一个包含 n 行和 p 列的数据集,这样数据集中的每个条目都包含一个实数。我正在寻找一种方法来对每行中的 p 列进行排名。这个排名的输出应该是一个长度 - p 的排名向量,它说明了关系。 所以
我正在尝试打印一个带分隔符的文件,而不必指定所有列。我可以接近,但数字列总是被引用: DATA _NULL_; SET SASHELP.CARS (obs = 5 keep = Make Mode
SAS 软件可以成功读取的最大文件大小是多少。(不考虑硬件限制) 提前致谢。 最佳答案 引用最近播放的电视广告,答案是“无限加 1”。 SAS 在读取操作期间对文件的大小没有任何限制,尽管您可能会遇到
我有一个包含变量 y、x1 和 x2 的数据集。我想找到适合模型的方程式: y = k1*x1c1 + k2 *x2c2 通过找到 k1、c1、k2 和 c2。我如何在 SAS 中执行此操作?具体来说
SAS中是否有用于定义数组中字母序列的简写? 许多语言都具有轻松执行此操作的机制,我想SAS也是如此,尽管我找不到它的引用。 例如,在R中,我可以做 > x x [1] "a" "b" "c" "d
我有两个 SAS 数据集。第一个相对较小,包含唯一的日期和相应的 ID: date dateID 1jan90 10 2jan90 15 3jan90 20 ... 第二个
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引起辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the he
我有一个主要是数值的变量,但是偶尔会有一个字符偷偷进入。因此,变量在 SAS 中存储为字符。我希望能够确定此字符变量中的各个值是否为数字。在知道哪些值是数字哪些是字符后,我想创建一个新的(数字)变量,
我是一名优秀的程序员,十分优秀!