我可以在用户点击提交上传服务器之前设置文件大小吗?

may I set file size when user click the submit upload server before?

我可以在用户点击提交上传服务器之前设置文件大小吗?

如果视频文件大小超过10MB,则文件无法选择或无法上传,我该怎么办?

这是我的代码

private void selectVideo() {
        Intent intent = new Intent();
        intent.setType("video/*");
        intent.setAction(Intent.ACTION_GET_CONTENT);
        startActivityForResult(intent, VIDEO);
    }

if(requestCode == VIDEO){
                image.setVisibility(View.GONE);
                previewImageView.setVisibility(View.VISIBLE);

                //video.setVisibility(View.VISIBLE);
                contentURI = data.getData();
                videoPath = getFilePathFromContentUri(contentURI, getContentResolver());
                Glide.with(this).load(contentURI).into(previewImageView);
                video.setVideoURI(contentURI);
                video.requestFocus();
                //video.start();
                MediaController mc= new MediaController(UploadActivity.this);
                video.setMediaController(mc);
                check_video = "ok";
            }

private void uploadFile() {
        progressDialog.show();

Map<String, RequestBody> map = new HashMap<>();
            //File file = new File(newvideoPath);
            String fullFilePath = PathUtil.getPathFromUri(this,contentURI);
            // Parsing any Media type file
            File file = new File(fullFilePath);
            String filename = getID+ "_"+ fullFilePath.substring(fullFilePath.lastIndexOf("/")+1);

            RequestBody requestBody = RequestBody.create(MediaType.parse("*/*"), file);
            map.put("file\"; filename=\"" + file.getName() + "\"", requestBody);
            ApiConfig getResponse = AppConfig.getApiClient().create(ApiConfig.class);
            Call<ServerResponse> call = getResponse.upload("token", map,imageName,userID,sp2,tag);
            call.enqueue(new Callback<ServerResponse>() {
                @Override
                public void onResponse(Call<ServerResponse> call, Response<ServerResponse> response) {
                    if (response.isSuccessful()){
                        if (response.body() != null){
                            progressDialog.dismiss();
                            ServerResponse serverResponse = response.body();
                            Toast.makeText(getApplicationContext(), serverResponse.getMessage(), Toast.LENGTH_SHORT).show();
                            Intent intent = new Intent(UploadActivity.this, MainActivity.class);
                            startActivity(intent);
                            finish();
                        }
                    }else {

                        Toast.makeText(getApplicationContext(), "problem uploading video", Toast.LENGTH_SHORT).show();
                    }
                }

                @Override
                public void onFailure(Call<ServerResponse> call, Throwable t) {

                    Log.v("Response gotten is", t.getMessage());
                    Toast.makeText(getApplicationContext(), "problem uploading video " + t.getMessage(), Toast.LENGTH_SHORT).show();

                }
            });

我试过在 php 上设置,但这不是我想要的,我希望我可以在 uploadActivity 上设置。如果文件大小超过10MB则无法选择文件

这里是你如何知道你的文件大小,然后你可以玩它。

File file = new File(fullFilePath);
long length = file.length();
length = length/1024;
Toast.makeText(getActivity(), "Video size:"+length+"KB",
Toast.LENGTH_LONG).show();