如何使用Java从Azure SAS读取文件

huangapple 未分类评论50阅读模式
英文:

How to read file from Azure SAS using Java

问题

我在Azure Blob Storage中有一个CSV文件的SAS URL我需要下载该文件并将其写入SQL数据库问题是如何使用SAS URL下载文件我尝试过使用`RestTemplate`,但是出现了`NullPointerException`。由于我对Java不太熟悉无法解决这个问题

String url = "https://orcatest.blob.core.windows.net/ABC/extract.csv?st=2020-04-";

HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.APPLICATION_OCTET_STREAM));

HttpEntity<String> entity = new HttpEntity<String>(headers);

ResponseEntity<String[]> response = restTemplate.exchange(link, HttpMethod.GET, entity, String[].class);
英文:

I have SAS URL of CSV file in Azure Bolb Storage. I need to download the file and write it to a SQL database. The question is, how to download the file using SAS URL. I tried with RestTemplate, but I'm getting a NullPointerException. Since I'm new to Java I can't figure this out.

String url=&quot;https://orcatest.blob.core.windows.net/ABC/extract.csv?st=2020-04-&quot;;

HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.APPLICATION_OCTET_STREAM));

HttpEntity&lt;String&gt; entity = new HttpEntity&lt;String&gt;(headers);

ResponseEntity&lt;String[]&gt; response = restTemplate.exchange(link, HttpMethod.GET, entity, String[].class);

huangapple
  • 本文由 发表于 2020年4月10日 21:33:03
  • 转载请务必保留本文链接:https://java.coder-hub.com/61141389.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定