Azure Function Blob存储连接:值“ *”的格式无效

时间:2019-05-25 20:40:58

标签: azure azure-functions azure-storage azure-storage-blobs

我正在编写v2 Azure函数,在其中我将访问Azure Blob存储。因为遇到麻烦,所以将其简化为这个最小的示例。

public class Payment extends AppCompatActivity {

private static final String TAG = "AddToDatabase";

private RecyclerView mRecyclerView2;
private ViewHolder2 mAdapter2;
private DatabaseReference mDatabaseReference2;
private FirebaseAuth.AuthStateListener mAuthListener;
private FirebaseDatabase mFirebaseDatabase;
private DatabaseReference myRef;
private List<Model2> mModel2;
private FirebaseAuth mAuth;
private TextView Total;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_payment);


    mRecyclerView2 = findViewById(R.id.recyclerview3);
    mRecyclerView2.setHasFixedSize(true);
    mRecyclerView2.setLayoutManager(new LinearLayoutManager(this));

    mModel2 = new ArrayList<>();
    mAuth = FirebaseAuth.getInstance();
    FirebaseUser user = mAuth.getCurrentUser();
    String userID = user.getUid();
    mAdapter2 = new ViewHolder2(Payment.this, mModel2);
    mRecyclerView2.setAdapter(mAdapter2);
    mDatabaseReference2 = FirebaseDatabase.getInstance().getReference(userID).child("Ordered");
    mDatabaseReference2.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
            double cost = 0;
            for (DataSnapshot postSnapshot : dataSnapshot.getChildren()) {
                Model2 model2 = postSnapshot.getValue(Model2.class);
                String stringValue = model2.getPrice();
                double price = Double.parseDouble(stringValue);

                cost = price + cost;
                String finaltotal = String.valueOf(cost);
                Total = findViewById(R.id.totalprice);
                Total.setText("Total Cost:" + finaltotal);

                mModel2.add(model2);
            }
            mAdapter2.notifyDataSetChanged();

        }

        @Override
        public void onCancelled(@NonNull DatabaseError databaseError) {

        }
    });

    mFirebaseDatabase = FirebaseDatabase.getInstance();
    myRef = mFirebaseDatabase.getReference();

    mAuthListener = new FirebaseAuth.AuthStateListener() {
        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
            FirebaseUser user = firebaseAuth.getCurrentUser();
            if (user != null) {
                // User is signed in
                Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid());
            } else {
                // User is signed out
                Log.d(TAG, "onAuthStateChanged:signed_out");
            }
        }
    };
    ///progressBar = findViewById(R.id.progressbar);

    // Read from the database
    myRef.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
            Object value = dataSnapshot.getValue();
            Log.d(TAG,"Value is"+value);
        }

        @Override
        public void onCancelled(@NonNull DatabaseError databaseError) {

        }
    });


}

public void onPayButton(View view) {

    //String newClick = Integer.toString(click1);
    FirebaseUser user = mAuth.getCurrentUser();
    String userID = user.getUid();
    myRef.child(userID).child("Ordered").child("5").child("food").setValue("Order Processing....");
    Intent intent = new Intent(Payment.this,Placeorder.class);
    startActivity(intent);
}

当我跑步并击中它时,我得到了错误

  

System.Private.CoreLib:执行函数Function1时发生异常。 Microsoft.WindowsAzure.Storage:值'*'的格式无效。 System.Net.Http:值'*'的格式无效。

如果我改变

namespace Test
{
    public static class Function1
    {
        [FunctionName("Function1")]
        public static async Task<IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "test")] HttpRequest req,
            ILogger log)
        {
            var azureStorage = CloudStorageAccount.Parse("UseDevelopmentStorage=true");
            var blobClient = azureStorage.CreateCloudBlobClient();
            var container = blobClient.GetContainerReference("migrated-load-sets-localhost");
            var blobReference = container.GetBlockBlobReference("11016093-2f6e-4631-97c1-04f8acfb2370");
            var memoryStream = new MemoryStream();
            var accessCondition = AccessCondition.GenerateIfExistsCondition();
            var blobRequestOptions = new BlobRequestOptions();
            await blobReference.DownloadToStreamAsync(memoryStream, accessCondition, blobRequestOptions, null);
            var text = System.Text.Encoding.UTF8.GetString(memoryStream.ToArray());
            return new OkObjectResult(text);
        }
    }
}

成为

var accessCondition = AccessCondition.GenerateIfExistsCondition();

有效。

我在调试中观察到var accessCondition = AccessCondition.GenerateEmptyCondition(); 等于accessCondition.IfMatchETag,所以看来这可能是罪魁祸首。

使用"*"时我做错什么了吗,还是库中有错误?

1 个答案:

答案 0 :(得分:0)

如果需要在下载文件之前检查blob是否存在,则只需

if(blobReference.ExistsAsync())
{
   //Download
}